Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: describe placeholder option for positional args #33

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>