Skip to content

Commit

Permalink
Added example to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
obany committed Jul 22, 2020
1 parent b878b1d commit 0fd81f1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,21 @@ jobs:

## CLI

The action is also available to use as a CLI, if you install the package `@iota/gh-tangle-release` you can run the following.
The core features are also available to use as a CLI independently of GitHub Actions.

If you install the npm package with:

```shell
npm install @iota/gh-tangle-release
```

You can then execute the following script.

```shell
gh-tangle-release
```

You will then be presented with the following options.

```shell
GitHub Tangle Release v0.7.0 🚀
Expand All @@ -115,4 +129,7 @@ Options:
--comment <string> An optional comment to include in the Tangle transaction payload
--explorer-url <string> Url of the explorer to use for exploration link (default: "https://utils.iota.org/transaction/:hash")
--help Display help
```


Example: gh-tangle-release --github-token a4d936470cb3d66f5434f787c2500bde9764f --owner my-org --repository my-repo --release-tag v1.0.1 --seed AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
```
16 changes: 10 additions & 6 deletions dist/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ program
.option("--explorer-url <string>", chalk_1.default.yellowBright("Url of the explorer to use for exploration link"), "https://utils.iota.org/transaction/:hash")
.helpOption("--help", chalk_1.default.yellowBright("Display help"));
if (process.argv.length === 2) {
program.help();
program.help(str => `${str}${createExample()}`);
}
else {
try {
Expand Down Expand Up @@ -82,10 +82,14 @@ else {
});
}
catch (err) {
program.help(str => {
console.log(str);
console.error(chalk_1.default.red(`Error: ${err.message}`));
return "";
});
program.help(str => `${str}${chalk_1.default.red(`Error: ${err.message}`)}`);
}
}
/**
* Show an example on the console.
* @returns The example text.
*/
function createExample() {
// eslint-disable-next-line max-len
return chalk_1.default.magenta("\nExample: gh-tangle-release --github-token a4d936470cb3d66f5434f787c2500bde9764f --owner my-org --repository my-repo --release-tag v1.0.1 --seed AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
}
2 changes: 1 addition & 1 deletion package-lock.json

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

17 changes: 11 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ program
chalk.yellowBright("Display help"));

if (process.argv.length === 2) {
program.help();
program.help(str => `${str}${createExample()}`);
} else {
try {
program.parse(process.argv);
Expand Down Expand Up @@ -92,10 +92,15 @@ if (process.argv.length === 2) {
process.exit(1);
});
} catch (err) {
program.help(str => {
console.log(str);
console.error(chalk.red(`Error: ${err.message}`));
return "";
});
program.help(str => `${str}${chalk.red(`Error: ${err.message}`)}`);
}
}

/**
* Show an example on the console.
* @returns The example text.
*/
function createExample(): string {
// eslint-disable-next-line max-len
return chalk.magenta("\nExample: gh-tangle-release --github-token a4d936470cb3d66f5434f787c2500bde9764f --owner my-org --repository my-repo --release-tag v1.0.1 --seed AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
}

0 comments on commit 0fd81f1

Please sign in to comment.