diff options
author | Peter Hatina <phatina@redhat.com> | 2012-09-13 09:38:12 +0200 |
---|---|---|
committer | Peter Hatina <phatina@redhat.com> | 2012-09-13 09:39:05 +0200 |
commit | 8de6088c8abf4ee1f392b97f63963065335ab977 (patch) | |
tree | 5176bc0ba16509811c8bedb3847276ffc4691f22 /cli-tools/cura/cura_options.py | |
parent | aefe1e49b515b55243096098f820367e53a58493 (diff) | |
download | openlmi-providers-8de6088c8abf4ee1f392b97f63963065335ab977.tar.gz openlmi-providers-8de6088c8abf4ee1f392b97f63963065335ab977.tar.xz openlmi-providers-8de6088c8abf4ee1f392b97f63963065335ab977.zip |
Introduce CLI tools
Diffstat (limited to 'cli-tools/cura/cura_options.py')
-rw-r--r-- | cli-tools/cura/cura_options.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/cli-tools/cura/cura_options.py b/cli-tools/cura/cura_options.py new file mode 100644 index 0000000..429740a --- /dev/null +++ b/cli-tools/cura/cura_options.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <http://www.gnu.org/licenses/>. + +import sys +import optparse + +class CuraBasicOptions(object): + def __init__(self, epil = ""): + optparse.OptionParser.format_epilog = lambda self, formatter: self.epilog + self.m_parser = optparse.OptionParser( + add_help_option = False, + epilog = epil) + self.m_parser.add_option("", "--help", + action="help", + help = "print this message") + self.m_parser.add_option("-h", "--hostname", + action = "store", + dest = "hostname", + help = "remote machine hostname") + self.m_parser.add_option("-u", "--username", + action = "store", + dest = "username", + help = "remote machine username") + self.m_parser.add_option("-p", "--password", + action = "store", + dest = "password", + help = "remote machine password") + + def parse(self, argv): + (self.m_options, self.m_pos_options) = self.m_parser.parse_args(argv[1:]) + + def printHelp(self): + self.m_parser.print_help() + + @property + def good(self): + return len(self.m_pos_options) == 0 + + @property + def hostname(self): + return self.m_options.hostname if self.m_options.hostname else "" + + @property + def username(self): + return self.m_options.username if self.m_options.username else "" + + @property + def password(self): + return self.m_options.password if self.m_options.password else "" |