forked from c4spar/deno-cliffy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display text override for default option value
This PR adds the following two features related to changing default value display for options. 1. `defaultText` option for options It is either a string or a function that transforms the default value into string. When set, it changes the help text of the default, while the underlying default value is used for processing. 2. `"secret"` input type This is exactly the same as string type, except it hides its default values on help text. Testing: new and existing unittests, playing with the build Fixes: c4spar#774
- Loading branch information
1 parent
1d5feed
commit 77ff46d
Showing
13 changed files
with
162 additions
and
31 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
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,45 @@ | ||
import { test } from "@cliffy/internal/testing/test"; | ||
import { | ||
assertEquals, | ||
assertMatch, | ||
assertNotMatch, | ||
assertRejects, | ||
} from "@std/assert"; | ||
import { Command } from "../../command.ts"; | ||
|
||
const cmd = new Command() | ||
.throwErrors() | ||
.option("-f, --flag [value:secret]", "description ...") | ||
.option("-d, --default [value:secret]", "description ...", { | ||
default: "DEFAULT", | ||
}) | ||
.option("--no-flag", "description ...") | ||
.action(() => {}); | ||
|
||
test("command - type - secret - with no value", async () => { | ||
const { options, args } = await cmd.parse(["-f"]); | ||
|
||
assertEquals(options, { flag: true, default: "DEFAULT" }); | ||
assertEquals(args, []); | ||
assertNotMatch(cmd.getHelp(), /"DEFAULT"/g); | ||
assertMatch(cmd.getHelp(), /"\*\*\*\*\*\*"/g); | ||
}); | ||
|
||
test("command - type - secret - with valid value", async () => { | ||
const { options, args } = await cmd.parse(["--flag", "value"]); | ||
|
||
assertEquals(options, { flag: "value", default: "DEFAULT" }); | ||
assertEquals(args, []); | ||
assertNotMatch(cmd.getHelp(), /"DEFAULT"/g); | ||
assertMatch(cmd.getHelp(), /"\*\*\*\*\*\*"/g); | ||
}); | ||
|
||
test("command - type - secret - no arguments allowed", async () => { | ||
await assertRejects( | ||
async () => { | ||
await cmd.parse(["-f", "value", "unknown"]); | ||
}, | ||
Error, | ||
`No arguments allowed for command "COMMAND".`, | ||
); | ||
}); |
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
Oops, something went wrong.