Skip to content

Commit 9a5e8c2

Browse files
Jesse Bordenfedericobucchi
authored andcommitted
Update CLI page copy data.
1 parent f3c9429 commit 9a5e8c2

File tree

4 files changed

+244
-6
lines changed

4 files changed

+244
-6
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
pre-code-text: In addition to detailed help screens and error messages out of the box, your ArgumentParser CLI tools can provide completion scripts and man pages, as well as extensibility through a JSON rendering of the interface.
2+
headline: ArgumentParser in use
3+
tabs:
4+
- label: CLI usage
5+
code: |-
6+
$ repeat yes --count 3
7+
yes
8+
yes
9+
yes
10+
11+
$ repeat --count
12+
Error: Missing value for '--count <count>'
13+
Help: --count <count> The number of times to repeat 'phrase'.
14+
Usage: repeat <phrase> [--count <count>]
15+
See 'repeat --help' for more information.
16+
17+
$ repeat -h
18+
USAGE: repeat <phrase> [--count <count>]
19+
20+
ARGUMENTS:
21+
<phrase> The phrase to repeat.
22+
23+
OPTIONS:
24+
--count <count> The number of times to repeat 'phrase'.
25+
-h, --help Show help information.'
26+
- label: Man page
27+
code: |-
28+
.\" "Generated by swift-argument-parser"
29+
.Dd May 21, 2025
30+
.Dt REPEAT 1
31+
.Os
32+
.Sh NAME
33+
.Nm repeat
34+
.Sh SYNOPSIS
35+
.Nm
36+
.Ar subcommand
37+
.Ar phrase
38+
.Op Fl -count Ar count
39+
.Op Fl -help
40+
.Sh DESCRIPTION
41+
.Bl -tag -width 6n
42+
.It Ar phrase
43+
The phrase to repeat.
44+
.It Fl -count Ar count
45+
The number of times to repeat 'phrase'.
46+
.It Fl h , -help
47+
Show help information.
48+
.It Em help
49+
Show subcommand help information.
50+
.Bl -tag -width 6n
51+
.It Ar subcommands...
52+
.El
53+
.El
54+
.Sh "EXIT STATUS"
55+
.Ex -std
56+
- label: Completion script
57+
code: |-
58+
#compdef repeat
59+
60+
__repeat_complete() {
61+
local -ar non_empty_completions=("${@:#(|:*)}")
62+
local -ar empty_completions=("${(M)@:#(|:*)}")
63+
_describe -V '' non_empty_completions -- empty_completions -P $'\'\''
64+
}
65+
66+
__repeat_custom_complete() {
67+
local -a completions
68+
completions=("${(@f)"$("${command_name}" "${@}" "${command_line[@]}")"}")
69+
if [[ "${#completions[@]}" -gt 1 ]]; then
70+
__repeat_complete "${completions[@]:0:-1}"
71+
fi
72+
}
73+
74+
__repeat_cursor_index_in_current_word() {
75+
if [[ -z "${QIPREFIX}${IPREFIX}${PREFIX}" ]]; then
76+
printf 0
77+
else
78+
printf %s "${#${(z)LBUFFER}[-1]}"
79+
fi
80+
}
81+
82+
_repeat() {
83+
emulate -RL zsh -G
84+
setopt extendedglob nullglob numericglobsort
85+
unsetopt aliases banghist
86+
87+
local -xr SAP_SHELL=zsh
88+
local -x SAP_SHELL_VERSION
89+
SAP_SHELL_VERSION="$(builtin emulate zsh -c 'printf %s "${ZSH_VERSION}"')"
90+
local -r SAP_SHELL_VERSION
91+
92+
local context state state_descr line
93+
local -A opt_args
94+
95+
local -r command_name="${words[1]}"
96+
local -ar command_line=("${words[@]}")
97+
local -ir current_word_index="$((CURRENT - 1))"
98+
99+
local -i ret=1
100+
local -ar arg_specs=(
101+
':phrase:'
102+
'--count[The number of times to repeat '\''phrase'\''.]:count:'
103+
'(-h --help)'{-h,--help}'[Show help information.]'
104+
)
105+
_arguments -w -s -S : "${arg_specs[@]}" && ret=0
106+
107+
return "${ret}"
108+
}
109+
110+
_repeat
111+
- label: JSON output
112+
code: |-
113+
{
114+
"command" : {
115+
"arguments" : [
116+
{
117+
"abstract" : "The phrase to repeat.",
118+
"isOptional" : false,
119+
"isRepeating" : false,
120+
"kind" : "positional",
121+
"shouldDisplay" : true,
122+
"valueName" : "phrase"
123+
},
124+
{
125+
"abstract" : "The number of times to repeat 'phrase'.",
126+
"isOptional" : true,
127+
"isRepeating" : false,
128+
"kind" : "option",
129+
"names" : [
130+
{
131+
"kind" : "long",
132+
"name" : "count"
133+
}
134+
],
135+
"preferredName" : {
136+
"kind" : "long",
137+
"name" : "count"
138+
},
139+
"shouldDisplay" : true,
140+
"valueName" : "count"
141+
},
142+
{
143+
"abstract" : "Show help information.",
144+
"isOptional" : true,
145+
"isRepeating" : false,
146+
"kind" : "flag",
147+
"names" : [
148+
{
149+
"kind" : "short",
150+
"name" : "h"
151+
},
152+
{
153+
"kind" : "long",
154+
"name" : "help"
155+
}
156+
],
157+
"preferredName" : {
158+
"kind" : "long",
159+
"name" : "help"
160+
},
161+
"shouldDisplay" : true,
162+
"valueName" : "help"
163+
}
164+
],
165+
"commandName" : "repeat",
166+
"shouldDisplay" : true,
167+
"subcommands" : [
168+
{
169+
"abstract" : "Show subcommand help information.",
170+
"arguments" : [
171+
{
172+
"isOptional" : true,
173+
"isRepeating" : true,
174+
"kind" : "positional",
175+
"shouldDisplay" : true,
176+
"valueName" : "subcommands"
177+
},
178+
{
179+
"isOptional" : true,
180+
"isRepeating" : false,
181+
"kind" : "flag",
182+
"names" : [
183+
{
184+
"kind" : "short",
185+
"name" : "h"
186+
},
187+
{
188+
"kind" : "long",
189+
"name" : "help"
190+
},
191+
{
192+
"kind" : "longWithSingleDash",
193+
"name" : "help"
194+
}
195+
],
196+
"preferredName" : {
197+
"kind" : "long",
198+
"name" : "help"
199+
},
200+
"shouldDisplay" : false,
201+
"valueName" : "help"
202+
}
203+
],
204+
"commandName" : "help",
205+
"shouldDisplay" : true,
206+
"superCommands" : [
207+
"repeat"
208+
]
209+
}
210+
]
211+
},
212+
"serializationVersion" : 0
213+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
headline: Build straightforward CLI tools with Argument Parser
2+
paragraphs:
3+
- 'You can quickly build full-featured command-line interfaces using the Swift Argument Parser library. Define commands by creating types with regular Swift properties. Link multiple commands to create rich command hierarchies.'
4+
- 'ArgumentParser provides a detailed help screen, clear error messages with near-miss checking, broad customization, and more.'
5+
link:
6+
text: Swift Argument Parser
7+
url: https://github.com/apple/swift-argument-parser
8+
code: |-
9+
import ArgumentParser
10+
@main
11+
struct Repeat: ParsableCommand {
12+
@Argument(help: "The phrase to repeat.")
13+
var phrase: String
14+
15+
@Option(help: "The number of times to repeat 'phrase'.")
16+
var count: Int? = nil
17+
18+
mutating func run() throws {
19+
let repeatCount = count ?? .max
20+
21+
for i in 1...repeatCount {
22+
print(phrase)
23+
}
24+
}
25+
}

_data/new-data/get-started/command-line-tools/full-width-text-code-column.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
headline: Handle process execution robustly with minimal boilerplate
1+
headline: Use Subprocess to handle process execution
22
paragraphs:
33
- 'Subprocess is a Swift library that provides precise, idiomatic control over launching and managing child processes. You can either collect the child process output asynchronously in full, or stream it in real time using AsyncSequence, making it easy to process output line-by-line as it arrives.'
44
- 'Subprocess gives you fine-grained control over environment variables, arguments, and many platform specific parameters, while embracing Swift’s concurrency features and type safety. Whether you’re building CLI tools or server-side Swift applications, swift-subprocess integrates cleanly.'

_data/new-data/get-started/command-line-tools/hero.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ link:
44
url: /getting-started/cli-swiftpm/
55
text: Get Started
66
boxes:
7-
- title: Quickly get started
8-
text: Many common command line features are auto-generated using the Swift Argument Parser package, including help commands and completion scripts.
9-
- title: Inherit Swift’s strengths
10-
text: Swift's speed and safety make it a great choice for building command line tools.
7+
- title: Simplified setup
8+
text: Auto-generate common command line features like help commands and completion scripts using the Swift Argument Parser package.
9+
- title: Language strengths
10+
text: Swift is fast, memory safe, and has robust string handling, making it a great choice for building command line tools.
1111
- title: Interoperable
12-
text: Swift’s interoperability enables you to use or wrap existing libraries in other languages within your CLI tools.
12+
text: Integrate and reuse existing libraries written in other languages like C and C++ by taking advantage of Swift's interoperability.

0 commit comments

Comments
 (0)