Revision f247bcb4 kamaki/cli/argument.py
b/kamaki/cli/argument.py | ||
---|---|---|
179 | 179 |
import kamaki |
180 | 180 |
print('kamaki %s'%kamaki.__version__) |
181 | 181 |
|
182 |
class HistoryArgument(FlagArgument): |
|
183 |
user_history_file=None |
|
184 |
def __init__(self, help='', parsed_name=None, default=False): |
|
185 |
super(HistoryArgument, self).__init__(help, parsed_name, default) |
|
186 |
|
|
187 |
def add(self, command_string): |
|
188 |
if self.user_history_file: |
|
189 |
f = open(self.user_history_file, 'a+') |
|
190 |
f.write(command_string) |
|
191 |
f.flush() |
|
192 |
f.close() |
|
193 |
|
|
194 |
def get(self, prefix='', limit=0): |
|
195 |
lines = [] |
|
196 |
if self.user_history_file: |
|
197 |
for line in open(self.user_history_file): |
|
198 |
line = line.trim() |
|
199 |
if len(line) > 0 and line.startswith(prefix): |
|
200 |
lines.append(line) |
|
201 |
return lines |
|
202 |
|
|
182 | 203 |
_arguments = dict(config = _config_arg, help = Argument(0, 'Show help message', ('-h', '--help')), |
183 | 204 |
debug = FlagArgument('Include debug output', ('-d', '--debug')), |
184 | 205 |
include = FlagArgument('Include protocol headers in the output', ('-i', '--include')), |
185 | 206 |
silent = FlagArgument('Do not output anything', ('-s', '--silent')), |
186 | 207 |
verbose = FlagArgument('More info at response', ('-v', '--verbose')), |
187 | 208 |
version = VersionArgument('Print current version', ('-V', '--version')), |
188 |
options = CmdLineConfigArgument(_config_arg, 'Override a config value', ('-o', '--options')) |
|
209 |
options = CmdLineConfigArgument(_config_arg, 'Override a config vale', ('-o', '--options')), |
|
210 |
history = HistoryArgument('Show user (prefixed) history', '--history') |
|
189 | 211 |
) |
190 | 212 |
|
191 | 213 |
def parse_known_args(parser): |
Also available in: Unified diff