this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› Fix cli options handling

+36 -28
+2 -2
README.md
··· 18 18 The command needs to be run inside of the git repository (this is used to detect if the repository uses github or gitlab) 19 19 20 20 ``` 21 - issurge [options] <file> [--] [<glab-args>...] 21 + issurge [options] <file> [--] [<submitter-args>...] 22 22 issurge --help 23 23 ``` 24 24 25 - - **&lt;glab-args&gt;** contains arguments that will be passed as-is to every `glab` command. 25 + - **&lt;submitter-args&gt;** contains arguments that will be passed as-is to every `glab` (or `gh`) command. 26 26 27 27 ### Options 28 28
+1 -2
exemple/README.md
··· 8 8 '--dry-run': True, 9 9 '--help': False, 10 10 '<file>': 'issues', 11 - '<glab-args>': []} 11 + '<submitter-args>': []} 12 12 @me ~by:lubin Making children from ~by:lubin @me 13 13 ~area:search Making children from ~by:lubin ~area:search @me 14 14 mettre un bouton "rechercher" ร  la place de "voir Made mettre un bouton "rechercher" (...) ~by:lubin ~area:search @me ··· 189 189 " -a @me -l feature -l by:lubin 190 190 Would run glab issue new -t "faire un arbre des admins avec nom prรฉnom annรฉes AE" -d "" -a @me -l feature -l by:lubin 191 191 ``` 192 -
+4 -3
issurge/main.py
··· 1 1 #!/usr/bin/env python 2 2 """ 3 3 Usage: 4 - issurge [options] <file> [--] [<glab-args>...] 4 + issurge [options] <file> [--] [<submitter-args>...] 5 5 issurge --help 6 6 7 - <glab-args> contains arguments that will be passed as-is to the end of all `glab' commands 7 + <submitter-args> contains arguments that will be passed as-is to the end of all `glab' commands 8 8 9 9 Options: 10 10 --dry-run Don't actually post the issues ··· 27 27 def run(): 28 28 opts = docopt(__doc__) 29 29 os.environ["ISSURGE_DEBUG"] = "1" if opts["--debug"] else "" 30 + os.environ["ISSURGE_DRY_RUN"] = "1" if opts["--dry-run"] else "" 30 31 31 32 debug(f"Running with options: {opts}") 32 33 print("Submitting issues...") 33 34 for issue in parse(Path(opts["<file>"]).read_text()): 34 - issue.submit() 35 + issue.submit(opts["<submitter-args>"])
+24 -21
issurge/parser.py
··· 1 + import os 1 2 import subprocess 2 - from typing import Any, Iterable 3 + from typing import Any, Iterable, NamedTuple 3 4 from urllib.parse import urlparse 4 - from rich import NamedTuple, print 5 5 6 - from issurge.utils import TAB, debug 6 + from rich import print 7 + 8 + from issurge.utils import NEWLINE, TAB, debug, debugging, dry_running 7 9 8 10 9 11 class Node: ··· 48 50 49 51 50 52 class Issue(NamedTuple): 51 - _cli_options: dict[str, Any] 52 53 title: str 53 54 description: str 54 55 labels: set[str] ··· 78 79 subprocess.run(["git", "remote", "get-url", "origin"]).stdout.decode() 79 80 ) 80 81 if remote_url.hostname == "github.com": 81 - self._github_submit() 82 + self._github_submit(submitter_args) 82 83 else: 83 - self._gitlab_submit() 84 + self._gitlab_submit(submitter_args) 84 85 85 - def _gitlab_submit(self): 86 + def _gitlab_submit(self, submitter_args: list[str]): 86 87 command = ["glab", "issue", "new"] 87 88 if self.title: 88 89 command += ["-t", self.title] ··· 93 94 command += ["-l", l] 94 95 if self.milestone: 95 96 command += ["-m", self.milestone] 96 - command.extend(self._cli_options["<glab-args>"]) 97 - if self._cli_options["--dry-run"] or self._cli_options["--debug"]: 98 - print( 99 - f"{'Would run' if self._cli_options['--dry-run'] else 'Running'} [white bold]{subprocess.list2cmdline(command)}[/]" 100 - ) 101 - if not self._cli_options["--dry-run"]: 102 - subprocess.run(command) 97 + command.extend(submitter_args) 98 + self._run(command) 103 99 104 - def _github_submit(self): 100 + def _github_submit(self, submitter_args: list[str]): 105 101 command = ["gh", "issue", "new"] 106 102 if self.title: 107 103 command += ["-t", self.title] ··· 112 108 command += ["-l", l] 113 109 if self.milestone: 114 110 command += ["-m", self.milestone] 115 - command.extend(self._cli_options["<glab-args>"]) 116 - if self._cli_options["--dry-run"] or self._cli_options["--debug"]: 111 + command.extend(submitter_args) 112 + self._run(command) 113 + 114 + def _run(self, command): 115 + if dry_running() or debugging(): 117 116 print( 118 - f"{'Would run' if self._cli_options['--dry-run'] else 'Running'} [white bold]{subprocess.list2cmdline(command)}[/]" 117 + f"{'Would run' if dry_running() else 'Running'} [white bold]{subprocess.list2cmdline(command)}[/]" 119 118 ) 120 - if not self._cli_options["--dry-run"]: 121 - subprocess.run(command) 119 + if not dry_running(): 120 + try: 121 + subprocess.run(command, check=True, capture_output=True) 122 + except subprocess.CalledProcessError as e: 123 + print( 124 + f"Calling [white bold]{e.cmd}[/] failed with code [white bold]{e.returncode}[/]:\n{NEWLINE.join(TAB + line for line in e.stderr.decode().splitlines())}" 125 + ) 122 126 123 127 # The boolean is true if the issue expects a description (ending ':') 124 128 @classmethod ··· 205 209 labels=current_labels, 206 210 assignees=current_assignees, 207 211 milestone=current_milestone, 208 - _cli_options=cli_options, 209 212 ) 210 213 211 214 if current_issue.title:
+5
issurge/utils.py
··· 1 1 from rich import print 2 2 import os 3 3 4 + def debugging(): 5 + return os.environ.get("ISSURGE_DEBUG") 6 + 7 + def dry_running(): 8 + return os.environ.get("ISSURGE_DRY_RUN") 4 9 5 10 def debug(*args, **kwargs): 6 11 if os.environ.get("ISSURGE_DEBUG"):