Skip to content

Commit

Permalink
fix(exos-scripts): Bump to exos-scripts v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nanovazquez committed Jul 1, 2020
1 parent 5c14d65 commit 62187eb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
indent_size = 2
max_line_length = 160
3 changes: 3 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint

- name: Publish package to npm
if: ${{ github.head_ref == 'master' }}
env:
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/node": "^13.11.1",
"@types/yargs-interactive": "^2.1.0",
"chalk": "^4.0.0",
"exos-scripts": "^1.0.0",
"exos-scripts": "^1.0.1",
"semantic-release": "^17.1.1",
"typescript": "^3.9.5"
}
Expand Down
16 changes: 8 additions & 8 deletions src/cli/get-command-options.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const defaultOptions = {
import type { Option } from "yargs-interactive";

const defaultOptions: Option = {
interactive: { describe: "Use interactive mode", default: true },
};

interface CommandOption {
default: unknown;
}

/**
* Check current options and decide what to do.
* If there is a missing property, run interactive mode
* using the other properties as default values
* @param commandOptions
*/
function getCommandOptions(commandOptions: CommandOption[]): unknown {
const toReturn = Object.assign({}, defaultOptions, commandOptions);
return toReturn;
function getCommandOptions(commandOptions: Option): Option {
return {
...defaultOptions,
...commandOptions,
};
}

export default getCommandOptions;
26 changes: 15 additions & 11 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import getCliVersion from "./get-cli-version";
import getCommandOptions from "./get-command-options";
import chalk from "chalk";

const yargsConfig = yargsInteractive();
// temporary fix until yargs.interactive is updated
import type { Argv } from "yargs";
import type { Option } from "yargs-interactive";

interface Interactive extends Argv {
usage(usage: string): Interactive;
interactive(options: Option): Interactive;
then(callback: (result: unknown) => unknown): Interactive;
}

const yargsConfig = yargsInteractive() as Interactive;

/*
* This CLI has two levels:
Expand All @@ -24,12 +34,10 @@ availableCommands.forEach((command) => {
// Run yargsInteractive again to obtain the command options.
// Use interactive mode is a property is missing.
// Execute the command handler at the end.
return yargsInteractive()
.interactive(commandOptions as any)
.then(commandHandler);
return yargsInteractive().interactive(commandOptions).then(commandHandler);
};

(yargsConfig as any).command(command);
yargsConfig.command(command);
});

export default function cli(): unknown {
Expand All @@ -41,10 +49,6 @@ export default function cli(): unknown {
console.log();

// Run yargsInteractive for the first time to obtain the command to use
return (yargsConfig as any)
.usage("$0 <command> [args]")
.demandCommand(1, 1, "You need to specify a command before moving on")
.help()
.wrap(null)
.version(cliVersion).argv;
return yargsConfig.usage("$0 <command> [args]").demandCommand(1, 1, "You need to specify a command before moving on").help().wrap(null).version(cliVersion)
.argv;
}
2 changes: 1 addition & 1 deletion src/exos-cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env node
#!/usr/bin/env node
import cli from "./cli";

// Run yargsInteractive for the first time to obtain the command to use.
Expand Down

0 comments on commit 62187eb

Please sign in to comment.