Skip to content

Commit

Permalink
feat(repo): Support copying files to all repos
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jul 22, 2018
1 parent 945f085 commit 2867879
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/repo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ Options

-s/--silent - Don't print subcommand output
--exit - Exit after first failure (non zero exit)

cp
--

Copies a file into each repository.

.. code-block::
$ maintain repo cp contributing.md .github/CONTRIBUTING.md
21 changes: 21 additions & 0 deletions maintain/commands/repo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import subprocess
from shutil import copyfile

import click
from git import Repo
Expand Down Expand Up @@ -101,3 +102,23 @@ def check(exit):
break

sys.exit(status)


@repo.command()
@click.argument('src', nargs=-1, type=click.Path(exists=True))
@click.argument('dst', nargs=1, type=click.Path())
def cp(src, dst):
status = 0

for (repo, path) in gather_repositories():
for filename in src:
destination = os.path.join(path, dst)

if os.path.exists(destination):
status = 1
print('Cannot copy to {}, {} exists'.format(repo, dst))
continue

copyfile(filename, destination)

sys.exit(status)

0 comments on commit 2867879

Please sign in to comment.