Skip to content

Commit 9d51454

Browse files
committed
Optional command-line keyword arguments
The optional command-line arguments(repo-dir and branch_name) are now keyword arguments; this allows us to avoid having to pass an empty branch_name() as the second argument if you want to pass in the repo_dir as the third argument. In the previous configuration, we used positional arguments(gitpuller git_url branch_name repo_dir) now we use keyword arguments: gitpuller git_url --branch_name [BRANCH_NAME] --repo_dir [REPO_DIR]
1 parent 1e57904 commit 9d51454

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

nbgitpuller/pull.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,14 @@ def main():
303303

304304
parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
305305
parser.add_argument('git_url', help='Url of the repo to sync')
306-
parser.add_argument('branch_name', default=None, help='Branch of repo to sync', nargs='?')
307-
parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
306+
parser.add_argument('--branch_name', default=None, required=False, help='Branch of repo to sync', nargs='?')
307+
parser.add_argument('--repo_dir', default='.', required=False, help='Path to clone repo under', nargs='?')
308308
args = parser.parse_args()
309309

310310
for line in GitPuller(
311311
args.git_url,
312312
args.repo_dir,
313-
branch=args.branch_name if args.branch_name else None
313+
branch=args.branch_name
314314
).pull():
315315
print(line)
316316

tests/test_gitpuller.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ def test_initialize():
9999
def command_line_test_helper(remote_path, branch, pusher_path):
100100
work_dir = "/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1]) + "/nbgitpuller"
101101
try:
102-
cmd = ['python3', 'pull.py', remote_path, branch, pusher_path]
102+
cmd = ['python3', 'pull.py', remote_path]
103+
if branch is not None:
104+
cmd += ['--branch_name', branch]
105+
if pusher_path is not None:
106+
cmd += ['--repo_dir', pusher_path]
103107
sp.check_output(
104108
cmd,
105109
cwd=work_dir
@@ -119,8 +123,9 @@ def test_command_line_existing_branch():
119123
assert subprocess_result
120124

121125

122-
def test_command_line_default_branch():
123-
branch = ""
126+
def test_command_line_no_branch_passed():
127+
# so it should use the default branch
128+
branch = None
124129
with Remote() as remote, Pusher(remote) as pusher:
125130
pusher.push_file('README.md', '1')
126131
remotepath = "file://%s" % os.path.abspath(remote.path)

0 commit comments

Comments
 (0)