diff --git a/cccli/commands/watch.py b/cccli/commands/watch.py new file mode 100644 index 0000000000000000000000000000000000000000..7f8a00ef5fc8634b767664dd031addd3347df34b --- /dev/null +++ b/cccli/commands/watch.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python +#coding=utf8 + +''' +CloudControl watch command +''' + +import time as systime + +from cccli.exception import * +from sjrpc.core.exceptions import * +from cccli.printer import Printer, color +from cccli.command import OptionCommand + + +class Command_watch(OptionCommand): + '''Show output of a repeated command''' + + def __init__(self, cli, argv0): + OptionCommand.__init__(self, cli, argv0) + self.set_usage("%prog [options] command [options]") + self.add_option("-n", "--interval", dest="seconds", type="float", default=1.0, + help="Define interval in seconds") + + def __call__(self, argv): + # Parse argline + self.parse_args(argv) + if len(self.args) == 0: + raise cmdBadArgument() + while True: + self.args = self.cli.aliases.substitute(self.args) + # Clear tty + self.cli.commands(["clear"]) + # Execute command + self.cli.commands(self.args) + systime.sleep(self.options.seconds)