Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

Commit

CLI reference: group flags and their environment variables

A command group's own flags get a table, such as g1t work's --workspace (also G1T_WORKSPACE).

G1T-Session:
ses_01m560bz6eeqc8v1hrrha03pap
syntaqxcommitted Parent4cc0907Browse files
2 files+50−110/2 viewed
+10−4
1414
1515 | Flag | |
1616 | --- | --- |
17−| `-R, --repo <[HOST/]OWNER/NAME>` | The repository, as [HOST/]OWNER/NAME, instead of the current directory's. |
17+| `-R, --repo <[HOST/]OWNER/NAME>` | The repository, as [HOST/]OWNER/NAME, instead of the current directory's. Also `G1T_REPO`. |
1818 | `--hostname <HOST>` | The g1t host, such as g1t.sh or git.example.com. |
1919 | `--json [FIELDS]` | Print JSON: every field, or only the comma-separated FIELDS. |
2020 | `--jq <EXPRESSION>` | Run a jq expression over the JSON and print what it gives. |
10871087
10881088 Work items: list, view, open, edit, link, close; claims, hand-offs, dependencies, events.
10891089
1090+Flags every `g1t work` command takes:
1091+
1092+| Flag | |
1093+| --- | --- |
1094+| `--workspace <SLUG>` | The workspace, by its slug; the current repository's when left out. Also `G1T_WORKSPACE`. |
1095+
10901096 ### g1t work list
10911097
10921098 List the workspace's work items; with --repo, those linked to that repository.
11521158 g1t work new --title "Rename the flag" --target acme/api --target acme/docs
11531159 ```
11541160
1155−Calls [`open_work_item`](/reference/api/work-items/open-work-item/), [`update_work_item`](/reference/api/work-items/update-work-item/), [`upload_attachment`](/reference/api/work-items/upload-attachment/).
1161+Calls [`open_work_item`](/reference/api/work-items/open-work-item/), [`update_work_item`](/reference/api/work-items/update-work-item/), [`upload_attachment`](/reference/api/work-items/upload-attachment/), [`upload_work_item_attachment`](/reference/api/work-items/upload-work-item-attachment/).
11561162
11571163 ### g1t work comment
11581164
11691175 | `-F, --body-file <FILE>` | Read the text from a file, or - for stdin. |
11701176 | `--attach <FILE>` | An image to show after the text (PNG, JPEG, GIF or WebP, at most 10 MB): uploaded, and its Markdown added. Repeat for more. |
11711177
1172−Calls [`add_work_item_comment`](/reference/api/work-items/add-work-item-comment/), [`upload_attachment`](/reference/api/work-items/upload-attachment/).
1178+Calls [`add_work_item_comment`](/reference/api/work-items/add-work-item-comment/), [`upload_work_item_attachment`](/reference/api/work-items/upload-work-item-attachment/).
11731179
11741180 ### g1t work edit
11751181
14541460 g1t pr comment --body 'The preview, after the fix:' --attach preview.png
14551461 ```
14561462
1457−Calls [`upload_attachment`](/reference/api/work-items/upload-attachment/).
1463+Calls [`upload_attachment`](/reference/api/work-items/upload-attachment/), [`upload_work_item_attachment`](/reference/api/work-items/upload-work-item-attachment/).
14581464
14591465 ## g1t api
14601466
+40−7
114114 if arg.is_last_set() {
115115 text = format!("After `--`. {text}");
116116 }
117+ if let Some(env) = arg.get_env() {
118+ let _ = write!(text, " Also `{}`.", env.to_string_lossy());
119+ }
117120 cell(text.trim())
118121 }
119122
120−fn command(out: &mut String, cmd: &Command, path: &str, depth: usize) {
123+/// The flags a command group takes for every command under it (`g1t work
124+/// --workspace`): its global ones that no command above it has.
125+fn group_flags<'a>(cmd: &'a Command, above: &[String]) -> Vec<&'a Arg> {
126+ cmd.get_arguments()
127+ .filter(|a| {
128+ a.is_global_set()
129+ && !a.is_hide_set()
130+ && !above.iter().any(|id| id == a.get_id().as_str())
131+ })
132+ .collect()
133+}
134+
135+fn command(out: &mut String, cmd: &Command, path: &str, depth: usize, above: &[String]) {
121136 if cmd.is_hide_set() || cmd.get_name() == "help" {
122137 return;
123138 }
131146 let _ = writeln!(out, "{}\n", sentence(&about.to_string()));
132147 }
133148 if !subs.is_empty() {
149+ let own = group_flags(cmd, above);
150+ if !own.is_empty() {
151+ let _ = writeln!(
152+ out,
153+ "Flags every `{path}` command takes:\n\n| Flag | |\n| --- | --- |"
154+ );
155+ for arg in &own {
156+ let _ = writeln!(out, "| `{}` | {} |", cell(&flag(arg)), describe(arg));
157+ }
158+ let _ = writeln!(out);
159+ }
160+ let mut above = above.to_vec();
161+ above.extend(own.iter().map(|a| a.get_id().to_string()));
134162 for sub in &subs {
135− command(out, sub, &format!("{path} {}", sub.get_name()), depth + 1);
163+ command(
164+ out,
165+ sub,
166+ &format!("{path} {}", sub.get_name()),
167+ depth + 1,
168+ &above,
169+ );
136170 }
137171 return;
138172 }
179213 let mut root = <crate::cli::Cli as clap::CommandFactory>::command();
180214 root.build();
181215 let mut out = HEAD.to_owned();
182− for arg in root
183− .get_arguments()
184− .filter(|a| a.is_global_set() && !a.is_hide_set())
185− {
216+ let globals = group_flags(&root, &[]);
217+ for arg in &globals {
186218 let _ = writeln!(out, "| `{}` | {} |", cell(&flag(arg)), describe(arg));
187219 }
188220 let _ = writeln!(out);
221+ let above: Vec<String> = globals.iter().map(|a| a.get_id().to_string()).collect();
189222 for sub in root.get_subcommands() {
190− command(&mut out, sub, &format!("g1t {}", sub.get_name()), 2);
223+ command(&mut out, sub, &format!("g1t {}", sub.get_name()), 2, &above);
191224 }
192225 out.trim_end().to_owned() + "\n"
193226 }

Comments

Sign in to comment.