8
8
9
9
10
10
async def handle_file_upload (
11
- * , repo , source , dest , overwrite , token , semaphore , session
11
+ * , repo , source , dest , overwrite , only_update , token , semaphore , session
12
12
):
13
13
check_exists_response = await check_exists (
14
14
session = session ,
@@ -23,19 +23,18 @@ async def handle_file_upload(
23
23
current_content = check_exists_response .get ("content" )
24
24
exists = current_sha is not None
25
25
26
- if exists and not overwrite :
27
- return click .style (
28
- "Skipped uploading {source} to {repo}/{path}: Found an existing copy." .format (
29
- source = source ,
30
- repo = repo ,
31
- path = dest ,
32
- ),
33
- fg = "blue" ,
34
- bold = True ,
35
- )
36
-
37
- else :
38
- if exists :
26
+ if exists :
27
+ if not overwrite :
28
+ return click .style (
29
+ "Skipped uploading {source} to {repo}/{path}: Found an existing copy." .format (
30
+ source = source ,
31
+ repo = repo ,
32
+ path = dest ,
33
+ ),
34
+ fg = "blue" ,
35
+ bold = True ,
36
+ )
37
+ else :
39
38
click .echo (
40
39
click .style (
41
40
"Found an existing copy at {repo}/{path} overwriting it's contents..." .format (
@@ -45,43 +44,44 @@ async def handle_file_upload(
45
44
),
46
45
)
47
46
48
- upload_response = await upload_content (
49
- session = session ,
50
- repo = repo ,
51
- source = source ,
52
- dest = dest ,
53
- token = token ,
54
- semaphore = semaphore ,
55
- exists = exists ,
56
- current_sha = current_sha ,
57
- current_content = current_content ,
58
- )
47
+ upload_response = await upload_content (
48
+ session = session ,
49
+ repo = repo ,
50
+ source = source ,
51
+ dest = dest ,
52
+ token = token ,
53
+ semaphore = semaphore ,
54
+ exists = exists ,
55
+ only_update = only_update ,
56
+ current_sha = current_sha ,
57
+ current_content = current_content ,
58
+ )
59
59
60
- if upload_response :
61
- return click .style (
62
- "Successfully uploaded '{source}' to {repo}/{dest}" .format (
63
- source = upload_response ["content" ]["name" ],
64
- repo = repo ,
65
- dest = upload_response ["content" ]["path" ],
66
- ),
67
- fg = "green" ,
68
- bold = True ,
69
- )
60
+ if upload_response :
61
+ return click .style (
62
+ "Successfully uploaded '{source}' to {repo}/{dest}" .format (
63
+ source = upload_response ["content" ]["name" ],
64
+ repo = repo ,
65
+ dest = upload_response ["content" ]["path" ],
66
+ ),
67
+ fg = "green" ,
68
+ bold = True ,
69
+ )
70
70
71
71
72
72
@click .command ()
73
- @click .option (
74
- "--org" ,
75
- prompt = click .style ("Enter your github user/organization" , bold = True ),
76
- help = "The github organization." ,
77
- )
78
73
@click .option (
79
74
"--token" ,
80
75
prompt = click .style ("Enter your personal access token" , bold = True ),
81
76
help = "Personal Access token with read and write access to org." ,
82
77
hide_input = True ,
83
78
envvar = "TOKEN" ,
84
79
)
80
+ @click .option (
81
+ "--org" ,
82
+ prompt = click .style ("Enter your github user/organization" , bold = True ),
83
+ help = "The github organization." ,
84
+ )
85
85
@click .option (
86
86
"--source" ,
87
87
prompt = click .style ("Enter path to source file" , fg = "blue" ),
@@ -98,16 +98,30 @@ async def handle_file_upload(
98
98
prompt = click .style (
99
99
"Should we overwrite existing contents at this path" , fg = "blue"
100
100
),
101
+ is_flag = True ,
102
+ show_default = True ,
101
103
help = "Overwrite existing files." ,
102
104
default = False ,
103
105
)
106
+ @click .option (
107
+ "--only-update/--no-only-update" ,
108
+ prompt = click .style (
109
+ "Should we only update existing files at this path" , fg = "blue"
110
+ ),
111
+ is_flag = True ,
112
+ show_default = True ,
113
+ help = "Only update existing files." ,
114
+ default = False ,
115
+ )
104
116
@click .option (
105
117
"--private/--no-private" ,
106
118
prompt = click .style ("Should we Include private repositories" , bold = True ),
119
+ is_flag = True ,
120
+ show_default = True ,
107
121
help = "Upload files to private repositories." ,
108
122
default = True ,
109
123
)
110
- async def main (org , token , source , dest , overwrite , private ):
124
+ async def main (org , token , source , dest , overwrite , only_update , private ):
111
125
"""Upload a file to all repositories owned by an organization/user."""
112
126
# create instance of Semaphore: max concurrent requests.
113
127
semaphore = asyncio .Semaphore (1000 )
@@ -171,6 +185,7 @@ async def main(org, token, source, dest, overwrite, private):
171
185
dest = dest ,
172
186
token = token ,
173
187
overwrite = overwrite ,
188
+ only_update = only_update ,
174
189
session = session ,
175
190
semaphore = semaphore ,
176
191
)
0 commit comments