diff --git a/README.md b/README.md index 803d6d7..236e831 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,18 @@ Then, to run the program, type $ climesync ``` +To view help, type + +``` +$ climesync -h +``` + +To view the program version and license information, type + +``` +$ climesync -v +``` + climesync accepts args like so: ``` diff --git a/climesync/climesync.py b/climesync/climesync.py index a82a0f3..6ed5a29 100755 --- a/climesync/climesync.py +++ b/climesync/climesync.py @@ -6,6 +6,8 @@ Options: -h --help Print this dialog + -v --version Print version and license information + and exit -c --connect= TimeSync Server URL -u --username= Username of user to authenticate as -p --password= Password of user to authenticate as @@ -82,6 +84,7 @@ "gu - get users\n" "du - delete user\n\n" "us - update user settings\n\n" + "v - print version information\n" "h - print this menu\n" "q - exit\n") @@ -112,6 +115,7 @@ ("uu", "update-user", commands.update_user), ("gu", "get-users", commands.get_users), ("du", "delete-user", commands.delete_user), + ("v", "version", commands.version), ] @@ -163,6 +167,7 @@ def scripting_mode(command_name, argv): def main(argv=None, test=False): # Command line arguments args = docopt(__doc__, argv=argv, options_first=True) + url = args['-c'] user = args['-u'] password = args['-p'] @@ -201,8 +206,8 @@ def main(argv=None, test=False): config_dict=config_dict, interactive=interactive) - if "error" in response or "pymesync error" in response or \ - "climesync error" in response: + if ("error" in response or "pymesync error" in response or + "climesync error" in response) and command != "version": util.print_json(response) if command: diff --git a/climesync/commands.py b/climesync/commands.py index 485f653..6b02894 100644 --- a/climesync/commands.py +++ b/climesync/commands.py @@ -5,6 +5,8 @@ import util +version_string = "Climesync 0.1.1" + ts = None # pymesync.TimeSync object autoupdate_config = True @@ -14,12 +16,15 @@ # climesync_command decorator class climesync_command(): - def __init__(self, select_arg=None, optional_args=False): + def __init__(self, select_arg=None, optional_args=False, + authenticated=True): self.select_arg = select_arg self.optional_args = optional_args + self.authenticated = authenticated def __call__(self, command): def wrapped_command(argv=None): + # If the command is being run in scripting mode if argv is not None: args = docopt(command.__doc__, argv=argv) @@ -43,7 +48,9 @@ def wrapped_command(argv=None): return command(**command_kwargs) else: - if util.check_token_expiration(ts): + # Bypass token check if the command doesn't require + # authentication + if util.check_token_expiration(ts) and self.authenticated: return {"error": "You need to sign in."} return command() @@ -1241,3 +1248,16 @@ def delete_user(username=None): return list() return ts.delete_user(username=username) + + +@climesync_command(authenticated=False) +def version(post_data=None): + """version + +Usage: version + +Examples: + climesync version + """ + + return version_string diff --git a/climesync/util.py b/climesync/util.py index c24d0d7..fdf6e4e 100644 --- a/climesync/util.py +++ b/climesync/util.py @@ -186,7 +186,6 @@ def print_json(response): print "" else: - print "I don't know how to print that!" print response diff --git a/testing/test_util.py b/testing/test_util.py index fa9d4b5..266b385 100644 --- a/testing/test_util.py +++ b/testing/test_util.py @@ -175,14 +175,6 @@ def test_print_json_dict(self, mock_stdout): assert "{}: {}".format(key, value) in mock_stdout.getvalue() - @patch("climesync.util.sys.stdout", new_callable=StringIO) - def test_print_json_invalid(self, mock_stdout): - test_response = "test" - - util.print_json(test_response) - - assert "I don't know how to print that!" in mock_stdout.getvalue() - def test_is_time(self): self.assertFalse(util.is_time("AhBm")) self.assertFalse(util.is_time("hm"))