Skip to content

Commit 803d918

Browse files
Merge pull request #6 from runsascoded/rw/create
Improve help text, refactor command registration, and fix test assertions
2 parents 0e907f9 + 65268be commit 803d918

File tree

14 files changed

+241
-175
lines changed

14 files changed

+241
-175
lines changed

src/ghpr/commands/clone.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,12 @@ def clone(
267267

268268
def register(cli):
269269
"""Register command with CLI."""
270-
cli.command()(
271-
opt('-d', '--directory', help='Directory to clone into (default: gh/{number})')(
272-
flag('-G', '--no-gist', help='Skip creating a gist')(
273-
flag('--no-comments', help='Skip cloning comments')(
274-
arg('spec', required=False)(
275-
clone
276-
)
277-
)
278-
)
279-
)
280-
)
270+
271+
@cli.command()
272+
@arg('spec', required=False)
273+
@flag('--no-comments', help='Skip cloning comments')
274+
@flag('-G', '--no-gist', help='Skip creating a gist')
275+
@opt('-d', '--directory', help='Directory to clone into (default: gh/{number})')
276+
def clone_cmd(spec, no_comments, no_gist, directory):
277+
"""Clone a PR or Issue description and comments to a local directory."""
278+
clone(spec, directory, no_gist, no_comments)

src/ghpr/commands/create.py

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,33 @@ def _finalize_created_item(
164164
proc.run('git', 'commit', '-m', f'Rename to {new_filename} and add {item_label} #{number} link', log=None)
165165
err(f"Updated {new_filename} with {item_label} link")
166166

167+
# Push updates to GitHub (link-def and footer)
168+
from . import push as push_module
169+
err("Pushing updates to GitHub...")
170+
push_module.push(
171+
gist=False,
172+
dry_run=False,
173+
footer=0, # Auto-detect footer based on gist existence
174+
no_footer=False,
175+
open_browser=False,
176+
images=False,
177+
gist_private=None,
178+
no_comments=True, # Don't sync comments during create
179+
force_others=False
180+
)
181+
182+
# Push to gist remote if it exists
183+
from ..gist import find_gist_remote
184+
gist_remote = find_gist_remote()
185+
if gist_remote:
186+
try:
187+
proc.run('git', 'push', gist_remote, 'main', log=None)
188+
err(f"Pushed to gist remote '{gist_remote}'")
189+
except Exception as e:
190+
err(f"Warning: Could not push to gist: {e}")
191+
else:
192+
err("No gist remote found, skipping gist push")
193+
167194
# Rename directory from gh/new to gh/{number}
168195
current_dir = Path.cwd()
169196
parent_dir = current_dir.parent
@@ -300,7 +327,17 @@ def create(
300327
yes: int,
301328
dry_run: bool,
302329
) -> None:
303-
"""Create a new PR or Issue from the current draft."""
330+
"""Create a new PR or Issue from the current draft.
331+
332+
By default, opens GitHub's web editor for interactive creation.
333+
Use -y to skip the web editor and create via API instead.
334+
"""
335+
# Validate draft flag with web editor mode
336+
if draft and yes == 0:
337+
err("Error: --draft flag requires -y (cannot use draft mode with web editor)")
338+
err("Use: ghpr create -d -y (or -yy for silent creation)")
339+
exit(1)
340+
304341
if issue:
305342
create_new_issue(repo, yes, dry_run)
306343
else:
@@ -623,30 +660,22 @@ def create_new_issue(
623660

624661
def register(cli):
625662
"""Register commands with CLI."""
663+
626664
# Register init command
627-
cli.command()(
628-
opt('-r', '--repo', help='Repository (owner/repo format)')(
629-
opt('-b', '--base', help='Base branch (default: repo default branch)')(
630-
init
631-
)
632-
)
633-
)
665+
@cli.command()
666+
@opt('-r', '--repo', help='Repository (owner/repo format)')
667+
@opt('-b', '--base', help='Base branch (default: repo default branch)')
668+
def init_cmd(repo, base):
669+
init(repo, base)
634670

635671
# Register create command
636-
cli.command()(
637-
opt('-b', '--base', help='Base branch (default: repo default branch)')(
638-
flag('-d', '--draft', help='Create as draft PR')(
639-
opt('-h', '--head', help='Head branch (default: auto-detect from parent repo)')(
640-
flag('-i', '--issue', help='Create an issue instead of a PR')(
641-
flag('-n', '--dry-run', help='Show what would be done without creating')(
642-
opt('-r', '--repo', help='Repository (owner/repo format, default: auto-detect)')(
643-
opt('-y', '--yes', count=True, default=0, help='Skip prompt: once = create then view, twice = create silently (default: open web editor during creation)')(
644-
create
645-
)
646-
)
647-
)
648-
)
649-
)
650-
)
651-
)
652-
)
672+
@cli.command(name='create', help='Create PR/Issue (default: web editor; use -y for API mode)')
673+
@opt('-y', '--yes', count=True, default=0, help='Skip web editor: -y = create via API then view, -yy = create silently (default: interactive web editor)')
674+
@opt('-r', '--repo', help='Repository (owner/repo format, default: auto-detect)')
675+
@flag('-n', '--dry-run', help='Show what would be done without creating')
676+
@flag('-i', '--issue', help='Create an issue instead of a PR')
677+
@opt('-h', '--head', help='Head branch (default: auto-detect from parent repo)')
678+
@flag('-d', '--draft', help='Create as draft PR (requires -y; incompatible with web editor)')
679+
@opt('-b', '--base', help='Base branch (default: repo default branch)')
680+
def create_cmd(yes, repo, dry_run, issue, head, draft, base):
681+
create(head, base, draft, issue, repo, yes, dry_run)

src/ghpr/commands/diff.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@ def diff(
122122

123123
def register(cli):
124124
"""Register command with CLI."""
125-
cli.command()(
126-
opt('-c', '--color', type=Choice(['auto', 'always', 'never']), default='auto',
127-
help='When to use colored output (default: auto)')(
128-
flag('--no-comments', help='Skip diffing comments')(
129-
diff
130-
)
131-
)
132-
)
125+
126+
@cli.command()
127+
@flag('--no-comments', help='Skip diffing comments')
128+
@opt('-c', '--color', type=Choice(['auto', 'always', 'never']), default='auto', help='When to use colored output (default: auto)')
129+
def diff_cmd(no_comments, color):
130+
diff(color, no_comments)

src/ghpr/commands/ingest_attachments.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,10 @@ def ingest_attachments(
203203

204204
def register(cli):
205205
"""Register command with CLI."""
206-
cli.command(name='ingest-attachments')(
207-
opt('-b', '--branch', help='Branch name for attachments (default: $GHPR_INGEST_BRANCH or "attachments")')(
208-
flag('--no-ingest', help='Disable attachment ingestion')(
209-
flag('-n', '--dry-run', help='Show what would be done without making changes')(
210-
ingest_attachments
211-
)
212-
)
213-
)
214-
)
206+
207+
@cli.command(name='ingest-attachments')
208+
@flag('-n', '--dry-run', help='Show what would be done without making changes')
209+
@flag('--no-ingest', help='Disable attachment ingestion')
210+
@opt('-b', '--branch', help='Branch name for attachments (default: $GHPR_INGEST_BRANCH or "attachments")')
211+
def ingest_attachments_cmd(dry_run, no_ingest, branch):
212+
ingest_attachments(branch, no_ingest, dry_run)

src/ghpr/commands/open.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def open_pr(gist: bool) -> None:
6868

6969
def register(cli):
7070
"""Register command with CLI."""
71-
cli.command(name='open')(
72-
flag('-g', '--gist', help='Open gist instead of PR')(
73-
open_pr
74-
)
75-
)
71+
72+
@cli.command(name='open')
73+
@flag('-g', '--gist', help='Open gist instead of PR')
74+
def open_cmd(gist):
75+
open_pr(gist)

src/ghpr/commands/pull.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,13 @@ def pull(
150150

151151
def register(cli):
152152
"""Register command with CLI."""
153-
cli.command()(
154-
flag('-g', '--gist', help='Also sync to gist')(
155-
flag('-n', '--dry-run', help='Show what would be done')(
156-
opt('-f/-F', '--footer/--no-footer', default=None, help='Add gist footer to PR (default: auto - add if gist exists)')(
157-
flag('-o', '--open', 'open_browser', help='Open PR in browser after pulling')(
158-
opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')(
159-
flag('--no-comments', help='Skip syncing comments')(
160-
pull
161-
)
162-
)
163-
)
164-
)
165-
)
166-
)
167-
)
153+
154+
@cli.command()
155+
@flag('--no-comments', help='Skip syncing comments')
156+
@opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')
157+
@flag('-o', '--open', 'open_browser', help='Open PR in browser after pulling')
158+
@opt('-f/-F', '--footer/--no-footer', default=None, help='Add gist footer to PR (default: auto - add if gist exists)')
159+
@flag('-n', '--dry-run', help='Show what would be done')
160+
@flag('-g', '--gist', help='Also sync to gist')
161+
def pull_cmd(no_comments, gist_private, open_browser, footer, dry_run, gist):
162+
pull(gist, dry_run, footer, open_browser, gist_private, no_comments)

src/ghpr/commands/push.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -625,24 +625,16 @@ def sync_to_gist(
625625

626626
def register(cli):
627627
"""Register command with CLI."""
628-
cli.command()(
629-
flag('-g', '--gist', help='Also sync to gist')(
630-
flag('-n', '--dry-run', help='Show what would be done without making changes')(
631-
opt('-f', '--footer', count=True, help='Footer level: -f = hidden footer, -ff = visible footer')(
632-
flag('-F', '--no-footer', help='Disable footer completely')(
633-
flag('-o', '--open', 'open_browser', help='Open PR in browser after pushing')(
634-
flag('-i', '--images', help='Upload local images and replace references')(
635-
opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')(
636-
flag('--no-comments', help='Skip pushing comment changes')(
637-
flag('-C', '--force-others', help='Allow pushing edits to other users\' comments (may fail at API level)')(
638-
push
639-
)
640-
)
641-
)
642-
)
643-
)
644-
)
645-
)
646-
)
647-
)
648-
)
628+
629+
@cli.command()
630+
@flag('-C', '--force-others', help='Allow pushing edits to other users\' comments (may fail at API level)')
631+
@flag('--no-comments', help='Skip pushing comment changes')
632+
@opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')
633+
@flag('-i', '--images', help='Upload local images and replace references')
634+
@flag('-o', '--open', 'open_browser', help='Open PR in browser after pushing')
635+
@flag('-F', '--no-footer', help='Disable footer completely')
636+
@opt('-f', '--footer', count=True, help='Footer level: -f = hidden footer, -ff = visible footer')
637+
@flag('-n', '--dry-run', help='Show what would be done without making changes')
638+
@flag('-g', '--gist', help='Also sync to gist')
639+
def push_cmd(force_others, no_comments, gist_private, images, open_browser, no_footer, footer, dry_run, gist):
640+
push(gist, dry_run, footer, no_footer, open_browser, images, gist_private, no_comments, force_others)

src/ghpr/commands/shell_integration.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def shell_integration(shell: str | None) -> None:
4545

4646
def register(cli):
4747
"""Register command with CLI."""
48-
cli.command(name='shell-integration')(
49-
arg('shell', type=Choice(['bash', 'zsh', 'fish']), required=False)(
50-
shell_integration
51-
)
52-
)
48+
49+
@cli.command(name='shell-integration')
50+
@arg('shell', type=Choice(['bash', 'zsh', 'fish']), required=False)
51+
def shell_integration_cmd(shell):
52+
shell_integration(shell)

src/ghpr/commands/show.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def show(gist: bool) -> None:
7171

7272
def register(cli):
7373
"""Register command with CLI."""
74-
cli.command()(
75-
flag('-g', '--gist', help='Only show gist URL')(
76-
show
77-
)
78-
)
74+
75+
@cli.command()
76+
@flag('-g', '--gist', help='Only show gist URL')
77+
def show_cmd(gist):
78+
show(gist)

src/ghpr/commands/upload.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,11 @@ def upload(
9999

100100
def register(cli):
101101
"""Register command with CLI."""
102-
cli.command()(
103-
arg('files', nargs=-1, required=True)(
104-
opt('-b', '--branch', default='assets', help='Branch name in gist (default: assets)')(
105-
opt('-f', '--format', type=Choice(['url', 'markdown', 'img', 'auto']), default='auto',
106-
help='Output format (default: auto - img for images, url for others)')(
107-
opt('-a', '--alt', help='Alt text for markdown/img format')(
108-
upload
109-
)
110-
)
111-
)
112-
)
113-
)
102+
103+
@cli.command()
104+
@opt('-a', '--alt', help='Alt text for markdown/img format')
105+
@opt('-f', '--format', type=Choice(['url', 'markdown', 'img', 'auto']), default='auto', help='Output format (default: auto - img for images, url for others)')
106+
@opt('-b', '--branch', default='assets', help='Branch name in gist (default: assets)')
107+
@arg('files', nargs=-1, required=True)
108+
def upload_cmd(alt, format, branch, files):
109+
upload(files, branch, format, alt)

0 commit comments

Comments
 (0)