Skip to content

Commit 0bfb078

Browse files
authored
feat: restructure CLI options (#108)
1 parent b8df755 commit 0bfb078

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

docs/git-draft.1.adoc

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ IMPORTANT: `git-draft` is WIP.
1818
== Synopsis
1919

2020
[verse]
21-
git draft [options] [--new] [--accept... | --no-accept] [--bot BOT]
22-
[--edit] [TEMPLATE [VARIABLE...] | -]
21+
git draft [options] [--new] [--accept... | --no-accept] [--bot BOT] [--edit]
22+
[TEMPLATE [VARIABLE...] | -]
2323
git draft [options] --quit
24-
git draft [options] --events [REF]
25-
git draft [options] --templates [--json | [--edit] TEMPLATE]
24+
git draft [options] --list-events [DRAFT]
25+
git draft [options] --list-templates
26+
git draft [options] --show-template [--edit] TEMPLATE
2627

2728

2829
== Description
@@ -56,10 +57,14 @@ By default, changes are not merged - keeping the working directory untouched.
5657
A different default can be set in the configuration file.
5758
When doing so, the `--no-accept` flag can be used to disable merging at CLI invocation time.
5859

60+
--batch::
61+
Disable interactive feedback.
62+
If a bot needs more information, its question will be persisted and displayed when creating the next draft.
63+
5964
-b BOT::
6065
--bot=BOT::
61-
Bot name.
62-
Defaults to the first bot defined in the configuration.
66+
Set bot name.
67+
The default is to use the first bot defined in the configuration.
6368

6469
-e::
6570
--edit::
@@ -77,6 +82,10 @@ Show help message and exit.
7782
--json::
7883
Use JSON output.
7984

85+
-E::
86+
--list-events::
87+
Display all events corresponding to a draft.
88+
8089
--log-path::
8190
Show log path and exit.
8291

@@ -92,10 +101,13 @@ Go back to the draft's origin branch, keeping the working directory's current st
92101
This will delete the draft branch and its upstream.
93102
Generated commits and the draft branch's final state remain available via `refs/drafts`.
94103

104+
-S::
105+
--show-template::
106+
Display the corresponding template's contents or, if the `--edit` option is set, open an interactive editor with its contents.
107+
95108
-T::
96-
--templates::
97-
With no argument, lists available templates.
98-
With an template name argument, displays the corresponding template's contents or, if the `--edit` option is set, opens an interactive editor with its contents.
109+
--list-templates::
110+
Lists available templates.
99111

100112
--version::
101113
Show version and exit.

src/git_draft/__main__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def callback(
7272

7373
add_command("new", help="create a new draft from a prompt")
7474
add_command("quit", help="return to original branch")
75-
add_command("events", help="list events")
76-
add_command("templates", short="T", help="show template information")
75+
add_command("list-events", short="E", help="list events")
76+
add_command("show-template", short="S", help="show template information")
77+
add_command("list-templates", short="T", help="list available templates")
7778

7879
parser.add_option(
7980
"-a",
@@ -215,26 +216,27 @@ async def run() -> None: # noqa: PLR0912 PLR0915
215216
drafter.quit_folio()
216217
case "quit":
217218
drafter.quit_folio()
218-
case "events":
219+
case "list-events":
219220
draft_id = args[0] if args else None
220221
for elem in drafter.list_draft_events(draft_id):
221222
print(elem)
222-
case "templates":
223-
if args:
224-
name = args[0]
225-
meta = find_prompt_metadata(name)
226-
if opts.edit:
227-
if meta:
228-
edit(path=meta.local_path(), text=meta.source())
229-
else:
230-
edit(path=PromptMetadata.local_path_for(name))
223+
case "show-template":
224+
if len(args) != 1:
225+
raise ValueError("Expected exactly one argument")
226+
name = args[0]
227+
meta = find_prompt_metadata(name)
228+
if opts.edit:
229+
if meta:
230+
edit(path=meta.local_path(), text=meta.source())
231231
else:
232-
if not meta:
233-
raise ValueError(f"No template named {name!r}")
234-
print(meta.source())
232+
edit(path=PromptMetadata.local_path_for(name))
235233
else:
236-
table = templates_table()
237-
print(table.to_json() if opts.json else table)
234+
if not meta:
235+
raise ValueError(f"No template named {name!r}")
236+
print(meta.source())
237+
case "list-templates":
238+
table = templates_table()
239+
print(table.to_json() if opts.json else table)
238240
case _:
239241
raise UnreachableError()
240242

0 commit comments

Comments
 (0)