Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit c1472d8

Browse files
committed
Add --force option to all cmdline utilities.
Option forces a yes answer where applicable, bails out on any prompt that requires non boolean input.
1 parent 19e89ae commit c1472d8

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

virt-clone

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def parse_args():
164164
# Misc options
165165
parser.add_option("-d", "--debug", action="store_true", dest="debug",
166166
help=_("Print debugging information"))
167+
parser.add_option("", "--force", action="store_true", dest="force",
168+
help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
169+
default=False)
167170

168171
(options,args) = parser.parse_args()
169172
return options
@@ -173,6 +176,7 @@ def main():
173176
options = parse_args()
174177

175178
cli.setupLogging("virt-clone", options.debug)
179+
cli.set_force(options.force)
176180

177181
logging.debug("start clone with HV " + options.connect)
178182

virt-image

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def parse_args():
139139
help=_("Print the libvirt XML, but do not start the domain"))
140140
parser.add_option("", "--boot", type="int", dest="boot",
141141
help=_("The zero-based index of the boot record to use"))
142+
parser.add_option("", "--force", action="store_true", dest="force",
143+
help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
144+
default=False)
142145

143146
(options,args) = parser.parse_args()
144147
if len(args) < 1:
@@ -162,6 +165,7 @@ def main():
162165
options = parse_args()
163166

164167
cli.setupLogging("virt-image", options.debug)
168+
cli.set_force(options.force)
165169

166170
conn = cli.getConnection(options.connect)
167171
type = None

virt-install

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ def parse_args():
273273
help=_("Print debugging information"))
274274
parser.add_option("", "--noreboot", action="store_true", dest="noreboot",
275275
help=_("Disables the automatic rebooting when the installation is complete."))
276+
parser.add_option("", "--force", action="store_true", dest="force",
277+
help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
278+
default=False)
276279

277280

278281
(options,args) = parser.parse_args()
@@ -338,6 +341,7 @@ def main():
338341
options = parse_args()
339342

340343
cli.setupLogging("virt-install", options.debug)
344+
cli.set_force(options.force)
341345
conn = cli.getConnection(options.connect)
342346
capabilities = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
343347

virtinst/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import Guest
3030

3131
MIN_RAM = 64
32+
force = False
3233

3334
#
3435
# Setup helpers
@@ -94,9 +95,15 @@ def getConnection(connect):
9495
# Prompting
9596
#
9697

98+
def set_force(val=True):
99+
global force
100+
force = val
101+
97102
def prompt_for_input(prompt = "", val = None):
98103
if val is not None:
99104
return val
105+
if force:
106+
raise RuntimeError(_("Force flag is set but input was required. Prompt was: %s" % prompt))
100107
print prompt + " ",
101108
return sys.stdin.readline().strip()
102109

@@ -110,6 +117,10 @@ def yes_or_no(s):
110117

111118
def prompt_for_yes_or_no(prompt):
112119
"""catches yes_or_no errors and ensures a valid bool return"""
120+
if force:
121+
logging.debug("Forcing return value of True to prompt '%s'")
122+
return True
123+
113124
while 1:
114125
input = prompt_for_input(prompt, None)
115126
try:

0 commit comments

Comments
 (0)