mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Rename opts so --help looks cleaner
This commit is contained in:
parent
281f96b8dd
commit
edf6da5c38
1 changed files with 12 additions and 13 deletions
25
bin/ansible
25
bin/ansible
|
@ -39,9 +39,8 @@ class Cli(object):
|
||||||
parser.add_option("-a", "--args", dest="module_args",
|
parser.add_option("-a", "--args", dest="module_args",
|
||||||
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
help="module arguments", default=C.DEFAULT_MODULE_ARGS)
|
||||||
parser.add_option('-o', '--one-line', dest='one_line', action='store_true',
|
parser.add_option('-o', '--one-line', dest='one_line', action='store_true',
|
||||||
help="output results on one line to make grepping easier, however will \
|
help="try to print output on one line")
|
||||||
not remove newlines from command output")
|
parser.add_option('-t', '--tree', dest='tree', default=None,
|
||||||
parser.add_option('-t', '--tree', dest='output_dest', default=None,
|
|
||||||
help="if specified, a directory name to save output to, one file per host")
|
help="if specified, a directory name to save output to, one file per host")
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
@ -76,17 +75,17 @@ class Cli(object):
|
||||||
options = self.options
|
options = self.options
|
||||||
|
|
||||||
# TODO: split into function
|
# TODO: split into function
|
||||||
if options.output_dest:
|
if options.tree:
|
||||||
if options.output_dest[0] != '/':
|
if options.tree[0] != '/':
|
||||||
options.output_dest = os.path.realpath(os.path.expanduser(options.output_dest))
|
options.tree = os.path.realpath(os.path.expanduser(options.tree))
|
||||||
if not os.path.exists(options.output_dest):
|
if not os.path.exists(options.tree):
|
||||||
try:
|
try:
|
||||||
os.makedirs(options.output_dest)
|
os.makedirs(options.tree)
|
||||||
except (IOError, OSError), e:
|
except (IOError, OSError), e:
|
||||||
print >> sys.stderr, "Could not make dir %s: %s" % (options.output_dest, e)
|
print >> sys.stderr, "Could not make dir %s: %s" % (options.tree, e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not os.access(options.output_dest, os.W_OK):
|
if not os.access(options.tree, os.W_OK):
|
||||||
print >> sys.stderr, "Cannot write to path %s" % options.output_dest
|
print >> sys.stderr, "Cannot write to path %s" % options.tree
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# now walk results and print output
|
# now walk results and print output
|
||||||
|
@ -145,8 +144,8 @@ class Cli(object):
|
||||||
if stderr:
|
if stderr:
|
||||||
buf += stderr
|
buf += stderr
|
||||||
print buf
|
print buf
|
||||||
if options.output_dest:
|
if options.tree:
|
||||||
path = os.path.join(options.output_dest, hostname)
|
path = os.path.join(options.tree, hostname)
|
||||||
fd = open(path, "w+")
|
fd = open(path, "w+")
|
||||||
fd.write(buf)
|
fd.write(buf)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue