Skip to content

Commit 6a361a0

Browse files
committed
Switched to subcommands
1 parent 9e25340 commit 6a361a0

5 files changed

Lines changed: 34 additions & 4 deletions

File tree

commands/__init__.py

Whitespace-only changes.

delete.py renamed to commands/delete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ async def list_repos(*, session, org, token):
153153
help="Destination path to delete.",
154154
)
155155
async def main(org, token, dest):
156-
"""Delete files for all repositories owned by an organization or user."""
156+
"""Delete a file in all repositories owned by an organization/user."""
157157

158158
# create instance of Semaphore: max concurrent requests.
159159
semaphore = asyncio.Semaphore(1000)

deploy.py renamed to commands/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ async def list_repos(*, session, org, token):
186186
"--overwrite/--no-overwrite", help="Overwrite existing files.", default=True
187187
)
188188
async def main(org, token, source, dest, overwrite):
189-
"""Deploy files to all repositories owned by an organization or user."""
189+
"""Deploy a file to all repositories owned by an organization/user."""
190190
# create instance of Semaphore: max concurrent requests.
191191
semaphore = asyncio.Semaphore(1000)
192192

main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import asyncclick as click
2+
import os
3+
4+
plugin_folder = os.path.join(os.path.dirname(__file__), 'commands')
5+
6+
7+
class GithubDeploy(click.MultiCommand):
8+
9+
def list_commands(self, ctx):
10+
rv = []
11+
for filename in os.listdir(plugin_folder):
12+
if filename.endswith('.py') and not filename.startswith('__init__'):
13+
rv.append(filename[:-3])
14+
rv.sort()
15+
return rv
16+
17+
def get_command(self, ctx, name):
18+
ns = {}
19+
fn = os.path.join(plugin_folder, name + '.py')
20+
with open(fn) as f:
21+
code = compile(f.read(), fn, 'exec')
22+
eval(code, ns, ns)
23+
return ns['main']
24+
25+
26+
main = GithubDeploy(
27+
help='Deploy changes to multiple github repositories using a single command.',
28+
)
29+
30+
if __name__ == '__main__':
31+
main()

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
url="https://github.com/tj-python/github-deploy",
2222
entry_points={
2323
"console_scripts": [
24-
"github-deploy=deploy:main",
25-
"github-delete=delete:main",
24+
"github-deploy=main:main",
2625
],
2726
},
2827
keywords=["yaml", "deploy", "poly repository", "github", "single configuration"],

0 commit comments

Comments
 (0)