diff --git a/organise_desktop/Cli.py b/organise_desktop/Cli.py old mode 100644 new mode 100755 index c40927f..031da93 --- a/organise_desktop/Cli.py +++ b/organise_desktop/Cli.py @@ -4,6 +4,7 @@ import os import sys import json +import click pwd = os.path.dirname(os.path.abspath(__file__)) @@ -11,80 +12,72 @@ folders = [x for x in Extensions] -def print_usage(): +@click.command() +@click.option( + "--undosort", + "-u", + is_flag=True, + help="Undo changes that were made.", +) +@click.option( + "--sched", + "-s", + is_flag=True, + help="Schedule an organization process to run." +) +@click.option( + "--desched", + "-d", + is_flag=True, + help="Remove a scheduled organization process." +) +@click.option( + "--ignore", + "-i", + type=str, + multiple=True, + help="Identify which file extension to exclude from organization. This should be passed for each file extension." +) +def cli( + undosched, + sched, + desched, + ignore +): """ - Prints usage of the Command Line interface + This is used to call a command line interface. """ - print("Usage: " + sys.argv[0] + " ") - print("-h -- Display help message.") - print("-u -- Undo") - print("-c --all -- Clean. If given --all then cleans all otherwise prompts") - print("-s --r -- start a schedule. removes a schedule if --r given") + if undosort: + undo() -if __name__ == '__main__': - - if len(sys.argv) <= 1: - print_usage() + elif sched: + schedule_start(folders) - elif sys.argv[1] == '-h': - print_usage() + elif desched: + schedule_end() - elif sys.argv[1] == '-u': - undo() - sys.exit() + elif ignore: + + tmp_ext_list = [] + for i in ignore: # Create a tuple with all the given extensions + tmp_ext_list.extend(i.split(',')) - elif sys.argv[1] == '-c': - - if len(sys.argv) == 3: - - if sys.argv[2] == '--all': - organise_desktop(Extensions) - sys.exit() - - else: - print("Invalid input") - sys.exit() - - elif len(sys.argv) == 2: - for x in enumerate(folders): - print('{} - {}'.format(x[0], x[1])) - - try: - exclude = input("Enter indexes of types to EXCLUDE\nEnter multiple by separating by a ,:\n") - except KeyboardInterrupt: - sys.exit() + extension_tuple = tuple([ # add periods to the start of extensions if not already there + x if x[0] == '.' else f".{x}" for x in tmp_ext_list + ]) - exclude_list = [int(i) for i in exclude.split(',')] - to_clean = {} - - for i in range(len(folders)): - if i not in exclude_list: - to_clean[folders[i]] = Extensions[folders[i]] - - - organise_desktop(to_clean) - - sys.exit() - - else: - print("Invalid Input") - sys.exit() + to_clean = { # create a dict that doesn't include the provided extensions, based on the extensions in the json file + category: [ + extension for extension in Extensions[category] if extension not in extension_tuple + ] for category in Extensions + } - elif sys.argv[1] == "-s": - - if len(sys.argv) == 2: - print("Starting schedule..") - schedule_start(folders) - - elif sys.argv[2] == '--r': - print("Removing schedule..") - schedule_end() - - else: - print("Invalid Input") - sys.exit() + organise_desktop(to_clean) else: - print("Invalid Input") - sys.exit() - + organise_desktop(Extensions) + + sys.exit() + +if __name__ == '__main__': + cli() diff --git a/requirements.txt b/requirements.txt index 91a2e07..440875e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ requests==2.18.4 six==1.11.0 urllib3==1.22 urwid==2.0.1 +Click>=7.0