Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ts): tsify lib/completion (#1601)
* chore(ts): tsify lib/completion * refactor(ts): get rid of Partial for self type Co-authored-by: Mael LE GUEN <mael.leguen@laposte.fr>
- Loading branch information
Showing
21 changed files
with
141 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CommandBuilder, FunctionCommandBuilder } from '../types' | ||
|
||
export function isFunctionCommandBuilder (builder: CommandBuilder): builder is FunctionCommandBuilder { | ||
return typeof builder === 'function' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CompletionFunction, SyncCompletionFunction } from '../types' | ||
|
||
export function isSyncCompletionFunction (completionFunction: CompletionFunction): completionFunction is SyncCompletionFunction { | ||
return completionFunction.length < 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './completion-function' | ||
export * from './command-builder' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { YargsInstance } from './yargs-instance' | ||
|
||
// To be completed later with other CommandBuilder flavours | ||
export type CommandBuilder = FunctionCommandBuilder | ||
|
||
export interface FunctionCommandBuilder { | ||
(y: YargsInstance): YargsInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { CommandBuilder } from './command-builder' | ||
|
||
export interface CommandHandler { | ||
builder: CommandBuilder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { CommandHandler } from './command-handler' | ||
import { Dictionary } from './dictionary' | ||
import { ParsedCommand } from './parsed-command' | ||
|
||
/** Instance of the command module. */ | ||
export interface CommandInstance { | ||
getCommandHandlers (): Dictionary<CommandHandler> | ||
parseCommand (cmd: string): ParsedCommand | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Parsed } from './parsed' | ||
|
||
export type CompletionFunction = SyncCompletionFunction | AsyncCompletionFunction | ||
|
||
export interface SyncCompletionFunction { | ||
(current: string, argv: Parsed): string[] | Promise<string[]> | ||
} | ||
|
||
export interface AsyncCompletionFunction { | ||
(current: string, argv: Parsed, done: (completions: string[]) => any): any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Parsed } from './parsed' | ||
import { CompletionFunction } from './completion-function' | ||
|
||
/** Instance of the completion module. */ | ||
export interface CompletionInstance { | ||
completionKey: string | ||
generateCompletionScript ($0: string, cmd: string): string | ||
getCompletion (args: string[], done: (completions: string[]) => any): any | ||
registerFunction(fn: CompletionFunction): void | ||
setParsed (parsed: Parsed): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** Yargs' context. */ | ||
export interface Context { | ||
commands: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export * from './command-builder' | ||
export * from './command-handler' | ||
export * from './command-instance' | ||
export * from './completion-function' | ||
export * from './completion-instance' | ||
export * from './context' | ||
export * from './dictionary' | ||
export * from './electron-process' | ||
export * from './options' | ||
export * from './parsed' | ||
export * from './parsed-command' | ||
export * from './usage-instance' | ||
export * from './yargs-instance' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Dictionary } from './dictionary' | ||
|
||
export interface Options { | ||
boolean: string[] | ||
configuration: Dictionary | ||
default: Dictionary | ||
/** Manually set keys */ | ||
key: Dictionary<boolean> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface ParsedCommand { | ||
cmd: string | ||
demanded: [] | ||
optional: [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Dictionary } from './dictionary' | ||
|
||
export interface Parsed { | ||
aliases: Dictionary<string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Dictionary } from './dictionary' | ||
|
||
/** Instance of the usage module. */ | ||
export interface UsageInstance { | ||
getCommands (): string[] | ||
getDescriptions (): Dictionary<string> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Context } from './context' | ||
import { Options } from './options' | ||
import { Parsed } from './parsed' | ||
|
||
/** Instance of the yargs module. */ | ||
export interface YargsInstance { | ||
argv: Parsed | ||
getContext (): Context | ||
getOptions (): Options | ||
parse (args: string[], shortCircuit: boolean): Parsed | ||
reset (): YargsInstance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters