-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify flags and configs for subcommands (#64)
Co-authored-by: itsspriyansh <[email protected]>
- Loading branch information
1 parent
dc71b8e
commit 8e6d44d
Showing
8 changed files
with
199 additions
and
28 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,34 @@ | ||
import colors from 'ansi-colors'; | ||
|
||
import Logger from '../../../logger'; | ||
import {AVAILABLE_SUBCOMMANDS} from '../constants'; | ||
import {Subcommand} from './interfaces'; | ||
|
||
export function showHelp(subcommand: string) { | ||
const subcmd = AVAILABLE_SUBCOMMANDS[subcommand]; | ||
|
||
const subcmdFlagUsage = subcmd.flags?.length ? ' [flag]' : ''; | ||
Logger.log(`Usage: ${colors.cyan(`npx @nightwatch/mobile-helper android ${subcommand}${subcmdFlagUsage} [configs]`)}\n`); | ||
|
||
const subcmdFlagsHelp = getSubcommandFlagsHelp(subcmd); | ||
if (subcmdFlagsHelp) { | ||
Logger.log(colors.yellow('Available flags:')); | ||
Logger.log(subcmdFlagsHelp); | ||
} | ||
} | ||
|
||
export const getSubcommandFlagsHelp = (subcmd: Subcommand) => { | ||
let output = ''; | ||
const longest = (xs: string[]) => Math.max.apply(null, xs.map(x => x.length)); | ||
|
||
if (subcmd.flags && subcmd.flags.length > 0) { | ||
const optionLongest = longest(subcmd.flags.map(flag => `--${flag.name}`)); | ||
subcmd.flags.forEach(flag => { | ||
const flagStr = `--${flag.name}`; | ||
const optionPadding = new Array(Math.max(optionLongest - flagStr.length + 3, 0)).join('.'); | ||
output += ` ${flagStr} ${colors.grey(optionPadding)} ${colors.gray(flag.description)}\n`; | ||
}); | ||
} | ||
|
||
return output; | ||
}; |
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,26 @@ | ||
// configs for subcommand options | ||
export interface CliConfig { | ||
name: string, | ||
alias: string[], | ||
description: string, | ||
usageHelp: string, | ||
} | ||
|
||
export interface Subcommand { | ||
description: string; | ||
cliConfigs?: CliConfig[]; | ||
flags: { | ||
name: string; | ||
description: string; | ||
cliConfigs?: CliConfig[]; | ||
}[]; | ||
} | ||
|
||
export interface AvailableSubcommands { | ||
[key: string]: Subcommand; | ||
} | ||
|
||
export interface SubcommandOptionsVerificationResult { | ||
subcommandFlag: string; | ||
configs: 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