Add support for multiple arguments #5

Merged
rissson merged 1 commits from master into master 2018-12-06 06:17:30 +01:00
2 changed files with 48 additions and 17 deletions
+30
View File
@@ -10,6 +10,8 @@
ad [path file or folder] ad [path file or folder]
``` ```
And it supports multiple arguments!
## Example ## Example
```bash ```bash
@@ -32,6 +34,34 @@ airport/
│ ├── captain.txt │ ├── captain.txt
``` ```
---
```bash
ad airport/ train-station/train.txt
```
```
airport/
├── plane/
train-station/
├── train.txt
```
---
```bash
# If your shell supports arguments expansion
ad airport/plane/{captain,passenger}.txt
```
```
airport/
├── plane/
│ ├── captain.txt
│ ├── passenger.txt
```
---
## Install ## Install
+18 -17
View File
@@ -6,25 +6,26 @@ import os
import click import click
@click.command() @click.command()
@click.argument('path') @click.argument('paths', nargs=-1)
@click.option('-cd/--change', is_flag=True, default=False, help='After creating the directories, change to the new deeper directory.') @click.option('-cd/--change', is_flag=True, default=False, help='After creating the directories, change to the new deeper directory.')
def advance_touch(path, cd): def advance_touch(paths, cd):
""" Make folder and files """ """ Make folders and files """
# Make folders for path in paths:
new_dirs = '/'.join(path.split('/')[0:-1]) # Make folders
if not os.path.exists(new_dirs) and new_dirs != '': new_dirs = '/'.join(path.split('/')[0:-1])
os.makedirs(new_dirs) if not os.path.exists(new_dirs) and new_dirs != '':
# Change directory os.makedirs(new_dirs)
if cd: # Change directory
cd_path = os.path.join(os.getcwd(), new_dirs) + '/' if cd:
os.chdir(cd_path) cd_path = os.path.join(os.getcwd(), new_dirs) + '/'
os.chdir(cd_path)
# Make file # Make file
if not path.endswith('/') and not os.path.isfile(path): if not path.endswith('/') and not os.path.isfile(path):
try: try:
open(path, 'w+').close() open(path, 'w+').close()
except IsADirectoryError: except IsADirectoryError:
pass pass
if __name__ == '__main__': if __name__ == '__main__':
advance_touch() advance_touch()