mirror of
https://github.com/flancian/garden.git
synced 2026-08-07 15:06:19 +00:00
Add argparse guard to potentially destructive script.
This commit is contained in:
@@ -1,9 +1,15 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import pathlib
|
import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--run', action='store_true', help='whether to actually run potentially destructive commands')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
for filename in pathlib.Path('.').glob('**/*.md'):
|
for filename in pathlib.Path('.').glob('**/*.md'):
|
||||||
new_filename = str(filename).lower().replace(' ', '-')
|
new_filename = str(filename).lower().replace(' ', '-')
|
||||||
command = ['git', 'mv', str(filename), new_filename]
|
command = ['git', 'mv', str(filename), new_filename]
|
||||||
print('would run: %s' % command)
|
print('would run: %s' % command)
|
||||||
# subprocess.run(command)
|
if args.run:
|
||||||
|
subprocess.run(command)
|
||||||
|
|||||||
Reference in New Issue
Block a user