Skip to content

Commit

Permalink
maintainers/scripts/update.py: support skipping prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
superherointj committed Jun 14, 2024
1 parent 23bcbb6 commit abce0bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion maintainers/scripts/update.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
, include-overlays ? false
, keep-going ? null
, commit ? null
, skip-prompt ? null
}:

let
Expand Down Expand Up @@ -184,6 +185,10 @@ let
that support it by adding
--argstr commit true
to skip prompt:
--argstr skip-prompt true
'';

/* Transform a matched package into an object for update.py.
Expand All @@ -204,7 +209,8 @@ let
optionalArgs =
lib.optional (max-workers != null) "--max-workers=${max-workers}"
++ lib.optional (keep-going == "true") "--keep-going"
++ lib.optional (commit == "true") "--commit";
++ lib.optional (commit == "true") "--commit"
++ lib.optional (skip-prompt == "true") "--skip-prompt";

args = [ packagesJson ] ++ optionalArgs;

Expand Down
8 changes: 5 additions & 3 deletions maintainers/scripts/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ async def start_updates(max_workers: int, keep_going: bool, commit: bool, packag
eprint(e)
sys.exit(1)

def main(max_workers: int, keep_going: bool, commit: bool, packages_path: str) -> None:
def main(max_workers: int, keep_going: bool, commit: bool, packages_path: str, skip_prompt: bool) -> None:
with open(packages_path) as f:
packages = json.load(f)

Expand All @@ -217,7 +217,8 @@ def main(max_workers: int, keep_going: bool, commit: bool, packages_path: str) -
eprint(f" - {package['name']}")
eprint()

confirm = input('Press Enter key to continue...')
confirm = '' if skip_prompt else input('Press Enter key to continue...')

if confirm == '':
eprint()
eprint('Running update for:')
Expand All @@ -236,12 +237,13 @@ def main(max_workers: int, keep_going: bool, commit: bool, packages_path: str) -
parser.add_argument('--keep-going', '-k', dest='keep_going', action='store_true', help='Do not stop after first failure')
parser.add_argument('--commit', '-c', dest='commit', action='store_true', help='Commit the changes')
parser.add_argument('packages', help='JSON file containing the list of package names and their update scripts')
parser.add_argument('--skip-prompt', '-s', dest='skip_prompt', action='store_true', help='Do not stop for prompts')

if __name__ == '__main__':
args = parser.parse_args()

try:
main(args.max_workers, args.keep_going, args.commit, args.packages)
main(args.max_workers, args.keep_going, args.commit, args.packages, args.skip_prompt)
except KeyboardInterrupt as e:
# Let’s cancel outside of the main loop too.
sys.exit(130)

0 comments on commit abce0bd

Please sign in to comment.