Initial public release of Warp.
Repo-Sync-Origin: warpdotdev/warp-internal@12af1d983b
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
let jackLastNameArgument: Argument = {
|
||||
name: "last-name",
|
||||
description: "Last name of the jack",
|
||||
values: [{ value: "Nichols" }, { value: "Nicholson" }],
|
||||
};
|
||||
let generatedArgument: Argument = {
|
||||
name: "generated-name",
|
||||
description: "Last name of the jack",
|
||||
values: [
|
||||
{
|
||||
generateSuggestionsFn: { script: "echo foobar" }
|
||||
}
|
||||
],
|
||||
};
|
||||
|
||||
export function activate(warp: Warp) {
|
||||
warp.completions.registerCommandSignature({
|
||||
command: {
|
||||
name: "jack",
|
||||
alias: "j",
|
||||
description: "Jack's special command",
|
||||
subcommands: [
|
||||
{
|
||||
name: "create",
|
||||
description: "Create a jack :D.",
|
||||
arguments: jackLastNameArgument,
|
||||
},
|
||||
{
|
||||
name: "delete",
|
||||
description: "Delete a jack :(.",
|
||||
arguments: jackLastNameArgument,
|
||||
},
|
||||
{
|
||||
name: "update",
|
||||
description: "Update a jack",
|
||||
arguments: [
|
||||
jackLastNameArgument,
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "generate",
|
||||
description: "Generate a jack",
|
||||
arguments: [
|
||||
generatedArgument
|
||||
]
|
||||
},
|
||||
],
|
||||
options: [
|
||||
{
|
||||
name: ["-s", "--special"],
|
||||
description: "Only operate on special jacks",
|
||||
arguments: {
|
||||
name: "level",
|
||||
description: "Level of specialness",
|
||||
values: [ { value: "1" }, { value: "2" }, { value: "3" }],
|
||||
}
|
||||
},
|
||||
{
|
||||
name: ["-c", "--cracker"],
|
||||
description: "Only operate on cracker jacks",
|
||||
},
|
||||
{
|
||||
name: "--eat",
|
||||
description: "Eat the jacks",
|
||||
requiredOptions: ["-c"],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
console.log("Successfully registered command signatures!");
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// A union type to express common command token delimiters. This is used by various
|
||||
// fields throughout the schema.
|
||||
type Delimiter = ',' | ':' | ';' | '/' | ' ' | '::';
|
||||
|
||||
// Add a new wrapper struct around the root Command object, which scales to provide a
|
||||
// semantically correct place for whole-command level configuration properties, like
|
||||
// supported CLI versions, signature author(s), way to resolve conflicts among CLIs with
|
||||
// the same name.
|
||||
interface CommandSignature {
|
||||
command: Command;
|
||||
|
||||
// See More configurable options parsing below.
|
||||
parseOptions?: {
|
||||
optionArgumentDelimiters?: Delimiter[];
|
||||
optionsMustPrecedeArguments?: boolean;
|
||||
flagsArePosixNoncompliant?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
// This is passed to generateAdditionalSuggestions and custom generator implementations.
|
||||
// See Support dynamic commands and Custom generators below.
|
||||
interface CompletionContext {
|
||||
// Tokens in the input buffer.
|
||||
tokens: string[];
|
||||
|
||||
// Path to shell executable.
|
||||
shell: string;
|
||||
|
||||
// The session's current working directory.
|
||||
pwd: string;
|
||||
|
||||
// Way to execute arbitrary shell command.
|
||||
// Maybe restrict this to running in restricted mode? How do we ensure this is safe?
|
||||
executeShellCommand: (command: string) => Promise<{
|
||||
exitCode: number;
|
||||
success: boolean;
|
||||
output: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
interface Command {
|
||||
name: string;
|
||||
alias?: string | string[];
|
||||
|
||||
// See Configure suggestion accept behavior below.
|
||||
insertValue?: string;
|
||||
|
||||
description?: string;
|
||||
arguments?: Argument | Argument[];
|
||||
subcommands?: Command[];
|
||||
options?: Option[];
|
||||
priority?: number;
|
||||
|
||||
// See Support dynamic subcommands below.
|
||||
runtimeOptionsAndSubcommands?: (ctx: CompletionContext) => {
|
||||
options?: Option[];
|
||||
subcommands?: Command[];
|
||||
};
|
||||
}
|
||||
|
||||
interface Argument {
|
||||
name: string;
|
||||
description?: string;
|
||||
// This is renamed from ArgumentType to ArgumentValue, because that's semantically what
|
||||
// this array is -- a collection of suggestions for argument values.
|
||||
values?: ArgumentValue[];
|
||||
optional?: boolean;
|
||||
|
||||
// See Alias support below.
|
||||
expandAlias?: (ctx: CompletionContext) => Promise<string[]>;
|
||||
|
||||
// See Multi-suggestion arguments below.
|
||||
arity?: {
|
||||
limit?: number | undefined,
|
||||
delimiter?: Delimiter[],
|
||||
},
|
||||
}
|
||||
|
||||
declare enum TemplateType {
|
||||
Files = "TemplateType.Files",
|
||||
Folders = "TemplateType.Folders" ,
|
||||
FilesAndFolders = "TemplateType.FilesAndFolders",
|
||||
}
|
||||
|
||||
interface Template {
|
||||
typeName: TemplateType;
|
||||
filterName?: string;
|
||||
}
|
||||
|
||||
interface ShellCommandGeneratorFn {
|
||||
script: string | ((tokens: string[]) => string);
|
||||
|
||||
// If left unspecified, splits the output of script on newlines by default. Splitting
|
||||
// on newlines by default is new behavior (currently the postProcess function is
|
||||
// required).
|
||||
postProcess?: (script_output: string) => GeneratorResults;
|
||||
}
|
||||
|
||||
// See Custom generators below.
|
||||
type CustomGeneratorFn = (ctx: CompletionContext) => Promise<GeneratorResults>;
|
||||
type GeneratorFn = ShellCommandGeneratorFn | CustomGeneratorFn;
|
||||
|
||||
interface SuggestionGenerator {
|
||||
generateSuggestionsFn: GeneratorFn,
|
||||
|
||||
options?: {
|
||||
customTrigger?: string
|
||||
}
|
||||
}
|
||||
|
||||
interface GeneratorResults {
|
||||
suggestions: Suggestion[];
|
||||
is_ordered?: boolean;
|
||||
}
|
||||
|
||||
declare type RootCommand = {
|
||||
is_root_command: true
|
||||
};
|
||||
|
||||
type ArgumentValue = Suggestion
|
||||
| Template
|
||||
| SuggestionGenerator
|
||||
| RootCommand;
|
||||
|
||||
interface Suggestion {
|
||||
value: string;
|
||||
displayValue?: string;
|
||||
description?: string;
|
||||
priority?: number;
|
||||
icon?: IconType;
|
||||
isHidden?: boolean;
|
||||
|
||||
insertValue?: string;
|
||||
|
||||
dangerous?: boolean;
|
||||
deprecated?: boolean;
|
||||
}
|
||||
|
||||
declare enum IconType {
|
||||
File = "IconType.File",
|
||||
Folder = "IconType.Folder",
|
||||
GitBranch = "IconType.GitBranch",
|
||||
}
|
||||
|
||||
interface Option {
|
||||
name: string | string[];
|
||||
|
||||
insertValue?: string;
|
||||
description?: string;
|
||||
arguments?: Argument | Argument[];
|
||||
required?: boolean;
|
||||
priority?: number;
|
||||
|
||||
dangerous?: boolean;
|
||||
deprecated?: boolean;
|
||||
|
||||
requiredOptions?: string[];
|
||||
incompatibleOptions?: string[];
|
||||
repeatable?: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
interface Warp {
|
||||
completions: Completions,
|
||||
}
|
||||
|
||||
interface Completions {
|
||||
registerCommandSignature: (signatures: CommandSignature | CommandSignature[]) => void,
|
||||
}
|
||||
|
||||
declare namespace console {
|
||||
function log(message: string): void;
|
||||
function err(message: string): void;
|
||||
}
|
||||
Reference in New Issue
Block a user