diff --git a/climesync/climesync.py b/climesync/climesync.py index 5eb1b82..6ed5a29 100755 --- a/climesync/climesync.py +++ b/climesync/climesync.py @@ -84,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") @@ -114,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), ] @@ -166,12 +168,6 @@ def main(argv=None, test=False): # Command line arguments args = docopt(__doc__, argv=argv, options_first=True) - if args['-v']: - print "Climesync 0.1.1" - with open("LICENSE", "r") as f: - print f.read() - return - url = args['-c'] user = args['-u'] password = args['-p'] @@ -210,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..714ad9c 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