Skip to content

Commit

Permalink
docs: describe placeholder option for positional args
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Molisani <[email protected]>
Signed-off-by: Michael Molisani <[email protected]>
  • Loading branch information
molisani committed Nov 4, 2024
1 parent 3cf23f9 commit 707501c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { buildCommand, type CommandContext } from "@stricli/core";

export const root = buildCommand({
func(this: CommandContext, _: {}, src: string, dest: string) {
this.process.stdout.write(`Copying file from ${src} to ${dest}`);
},
parameters: {
positional: {
kind: "tuple",
parameters: [
{
brief: "Source file",
parse: String,
placeholder: "src",
},
{
brief: "Destination path",
parse: String,
placeholder: "dest",
},
],
},
},
docs: {
brief: "Example for live playground with positional arguments labeled by placeholders",
},
});
10 changes: 10 additions & 0 deletions docs/docs/features/argument-parsing/positional.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,13 @@ import DefaultTupleArgumentCode from "./examples/default-tuple-argument.txt";
<StricliPlayground filename="default-tuple-argument" rootExport="root" appName="run" defaultInput="">
{DefaultTupleArgumentCode}
</StricliPlayground>

## Placeholder

Positional arguments don't truly have names as a name cannot be included in the input (for named arguments, use [flags](./flags.mdx) instead). However, they still have a semantic meaning and it can be useful to refer to it with a name for simplicity. To avoid confusion with named flags, you can specify a "placeholder" for positional arguments. These placeholders are used in the auto-generated usage lines and in the help text.

import PlaceholderArgumentCode from "./examples/placeholder-argument.txt";

<StricliPlayground filename="placeholder-argument" rootExport="root" appName="run" defaultInput="--help">
{PlaceholderArgumentCode}
</StricliPlayground>

0 comments on commit 707501c

Please sign in to comment.