|
| 1 | +import json_manager |
| 2 | +import click |
| 3 | + |
| 4 | +@click.group() |
| 5 | +def PSExec(): |
| 6 | + pass |
| 7 | + |
| 8 | +@PSExec.command() |
| 9 | +@click.option('--name','-n',required=True,help='Name of the script') |
| 10 | +@click.option('--desc','-d',required=True,help='Description of the script') |
| 11 | +@click.option('--path','-p',required=True,help='Path of the script') |
| 12 | +@click.option('--module','-m',required=True,help='Module of the script') |
| 13 | +@click.option('--tags','-t',required=True,multiple=True,help='Tags of the script') |
| 14 | +@click.pass_context |
| 15 | +def new(ctx,name,desc,path,module,tags): |
| 16 | + if not name or not desc or not path or not module or not tags: |
| 17 | + ctx.fail('The all fields are required.') |
| 18 | + else: |
| 19 | + data = json_manager.read_json() |
| 20 | + newId = len(data) + 1 |
| 21 | + |
| 22 | + folder = json_manager.create_folder('./scripts') |
| 23 | + |
| 24 | + if not folder: |
| 25 | + print(f"The folder scripts already exists.") |
| 26 | + |
| 27 | + moveScript = json_manager.move_file(path,'./scripts') |
| 28 | + |
| 29 | + if not moveScript: |
| 30 | + ctx.fail('Could not be moved the file to the folder scripts.') |
| 31 | + |
| 32 | + newScript = { |
| 33 | + 'id': newId, |
| 34 | + 'name': name, |
| 35 | + 'description': desc, |
| 36 | + 'path': moveScript, |
| 37 | + 'module': module, |
| 38 | + 'tags': tags, |
| 39 | + } |
| 40 | + data.append(newScript) |
| 41 | + json_manager.write_json(data) |
| 42 | + print(f"The Script - {name} created successfully with id {newId}") |
| 43 | + |
| 44 | +@PSExec.command() |
| 45 | +def scripts(): |
| 46 | + data = json_manager.read_json() |
| 47 | + |
| 48 | + if len(data) == 0: |
| 49 | + print("Don't exist scripts, please add scripts for use.") |
| 50 | + else: |
| 51 | + print("NAME".ljust(20),"DESC".ljust(len(data[0]['description'])),"MODULE".ljust(20), "TAGS".ljust(20)) |
| 52 | + for script in data: |
| 53 | + tagg = '' |
| 54 | + for tag in script['tags']: |
| 55 | + tagg += '[' + tag + ']' |
| 56 | + |
| 57 | + print(script['name'].ljust(20),script['description'].ljust(20),script['module'].ljust(20),tagg.ljust(20)) |
| 58 | + |
| 59 | +@PSExec.command() |
| 60 | +@click.option('--name','-n',required=True,help='Name of the script') |
| 61 | +@click.pass_context |
| 62 | +def exec(ctx,name): |
| 63 | + execFile = json_manager.exec_file(name) |
| 64 | + if execFile == 0: |
| 65 | + print(f"The {name} script has been executed successfully.") |
| 66 | + else: |
| 67 | + print(f"The {name} script has not been executed correctly.") |
| 68 | + |
| 69 | + |
| 70 | +if __name__ == '__main__': |
| 71 | + PSExec() |
0 commit comments