2019-04-25 17:39:16 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 21:46:01 +00:00
|
|
|
declare module 'capitano' {
|
|
|
|
export function parse(argv: string[]): Cli;
|
|
|
|
|
|
|
|
export interface Cli {
|
|
|
|
command: string;
|
|
|
|
options: {};
|
2020-04-30 16:22:51 +00:00
|
|
|
global: {
|
|
|
|
help?: boolean;
|
|
|
|
};
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:40:13 +00:00
|
|
|
export interface OptionDefinition {
|
2017-12-20 21:46:01 +00:00
|
|
|
signature: string;
|
2020-04-28 15:52:46 +00:00
|
|
|
description?: string;
|
2017-12-20 21:46:01 +00:00
|
|
|
parameter?: string;
|
|
|
|
boolean?: boolean;
|
2020-02-10 18:25:15 +00:00
|
|
|
required?: string;
|
2017-12-20 21:46:01 +00:00
|
|
|
alias?: string | string[];
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:40:13 +00:00
|
|
|
export interface CommandDefinition<P = {}, O = {}> {
|
2017-12-20 21:46:01 +00:00
|
|
|
signature: string;
|
2020-04-30 16:22:51 +00:00
|
|
|
description?: string;
|
|
|
|
help?: string;
|
2019-05-28 16:31:18 +00:00
|
|
|
options?: Partial<OptionDefinition[]>;
|
2020-04-30 16:22:51 +00:00
|
|
|
permission?: string; // This should be 'user' but without full typescript we cannot enforce it
|
2018-05-22 15:12:51 +00:00
|
|
|
root?: boolean;
|
|
|
|
primary?: boolean;
|
2020-04-02 13:26:52 +00:00
|
|
|
hidden?: boolean;
|
2019-05-28 16:31:18 +00:00
|
|
|
action(params: P, options: Partial<O>, done: () => void): void;
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:40:13 +00:00
|
|
|
export interface Command {
|
|
|
|
signature: Signature;
|
|
|
|
options: Option[];
|
|
|
|
isWildcard(): boolean;
|
2020-04-28 15:52:46 +00:00
|
|
|
// You can pass whatever you want into a capitano command and it gets added as a prop
|
|
|
|
[key: string]: any;
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:40:13 +00:00
|
|
|
export interface Signature {
|
|
|
|
hasParameters(): boolean;
|
|
|
|
hasVariadicParameters(): boolean;
|
|
|
|
isWildcard(): boolean;
|
|
|
|
allowsStdin(): boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface Option {
|
|
|
|
signature: Signature;
|
|
|
|
alias: string | string[];
|
|
|
|
boolean: boolean;
|
|
|
|
parameter: string;
|
|
|
|
required: boolean | string;
|
|
|
|
}
|
|
|
|
|
2020-04-30 16:22:51 +00:00
|
|
|
export function command<P, O>(command: CommandDefinition<P, O>): void;
|
2017-12-20 21:46:01 +00:00
|
|
|
|
|
|
|
export const state: {
|
2018-01-09 15:05:24 +00:00
|
|
|
getMatchCommand: (
|
|
|
|
signature: string,
|
|
|
|
callback: (e: Error, cmd: Command) => void,
|
|
|
|
) => void;
|
2020-04-28 15:52:46 +00:00
|
|
|
commands: Command[];
|
|
|
|
globalOptions: OptionDefinition[];
|
2017-12-20 21:46:01 +00:00
|
|
|
};
|
2020-04-30 16:22:51 +00:00
|
|
|
|
|
|
|
export function execute(
|
|
|
|
args: any,
|
|
|
|
callback: (err?: any, result: any) => void,
|
|
|
|
): void;
|
|
|
|
export function globalOption(option: OptionDefinition): void;
|
|
|
|
export function permission(
|
|
|
|
permissionName: string,
|
|
|
|
callback: (done: () => void) => void,
|
|
|
|
): void;
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|