updatecommandline.py (1826B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 6 def create_parser(): 7 from wptrunner import wptcommandline 8 9 parser = wptcommandline.create_parser_update() 10 parser.add_argument( 11 "--upstream", 12 dest="upstream", 13 action="store_true", 14 default=None, 15 help="Push local changes to upstream repository even when not syncing", 16 ) 17 parser.add_argument( 18 "--no-upstream", 19 dest="upstream", 20 action="store_false", 21 default=None, 22 help="Dont't push local changes to upstream repository when syncing", 23 ) 24 parser.add_argument( 25 "--token-file", 26 action="store", 27 type=wptcommandline.abs_path, 28 help="Path to file containing github token", 29 ) 30 parser.add_argument("--token", action="store", help="GitHub token to use") 31 return parser 32 33 34 def check_args(kwargs): 35 from wptrunner import wptcommandline 36 37 kwargs = wptcommandline.check_args_update(kwargs) 38 kwargs["upstream"] = ( 39 kwargs["upstream"] if kwargs["upstream"] is not None else kwargs["sync"] 40 ) 41 42 if kwargs["upstream"]: 43 if kwargs["rev"]: 44 raise ValueError("Setting --rev with --upstream isn't supported") 45 if kwargs["token"] is None: 46 if kwargs["token_file"] is None: 47 raise ValueError("Must supply either a token file or a token") 48 with open(kwargs["token_file"]) as f: 49 token = f.read().strip() 50 kwargs["token"] = token 51 del kwargs["token_file"] 52 return kwargs 53 54 55 def parse_args(): 56 parser = create_parser() 57 kwargs = vars(parser.parse_args()) 58 return check_args(kwargs)