/*
* virsh-edit.c: Implementation of generic virsh *-edit intelligence
*
- * Copyright (C) 2012 Red Hat, Inc.
+ * Copyright (C) 2012, 2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
char *doc_reread = NULL;
const char *msg = NULL;
bool edit_success = false;
+ bool relax_avail = false;
/* Get the XML configuration of the object. */
doc = (EDIT_GET_XML);
goto edit_cleanup;
reedit:
+
+#ifdef EDIT_RELAX
+ relax_avail = true;
+#endif
+
/* Start the editor. */
if (vshEditFile(ctl, tmp) == -1)
goto edit_cleanup;
msg = _("Failed.");
if (msg) {
- int c = vshAskReedit(ctl, msg);
+ int c = vshAskReedit(ctl, msg, relax_avail);
switch (c) {
case 'y':
goto reedit;
goto edit_cleanup;
break;
+#ifdef EDIT_RELAX
+ case 'i':
+ if (relax_avail) {
+ EDIT_RELAX;
+ relax_avail = false;
+ goto redefine;
+ break;
+ }
+ /* fall-through */
+#endif
+
default:
vshError(ctl, "%s", msg);
break;
/*
* virsh.c: a shell to exercise the libvirt API
*
- * Copyright (C) 2005, 2007-2014 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* edited file.
*
* Returns 'y' if he wants to
- * 'f' if he forcibly wants to
* 'n' if he doesn't want to
+ * 'i' if he wants to try defining it again while ignoring validation
+ * 'f' if he forcibly wants to
* -1 on error
* 0 otherwise
*/
int
-vshAskReedit(vshControl *ctl, const char *msg)
+vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail)
{
int c = -1;
return -1;
while (true) {
- /* TRANSLATORS: For now, we aren't using LC_MESSAGES, and the user
- * choices really are limited to just 'y', 'n', 'f' and '?' */
- vshPrint(ctl, "\r%s %s", msg, _("Try again? [y,n,f,?]:"));
+ vshPrint(ctl, "\r%s %s %s: ", msg, _("Try again?"),
+ relax_avail ? "[y,n,i,f,?]" : "[y,n,f,?]");
c = c_tolower(getchar());
if (c == '?') {
"",
_("y - yes, start editor again"),
_("n - no, throw away my changes"),
+ NULL);
+
+ if (relax_avail) {
+ vshPrintRaw(ctl,
+ _("i - turn off validation and try to redefine again"),
+ NULL);
+ }
+
+ vshPrintRaw(ctl,
_("f - force, try to redefine again"),
_("? - print this help"),
NULL);
continue;
- } else if (c == 'y' || c == 'n' || c == 'f') {
+ } else if (c == 'y' || c == 'n' || c == 'f' ||
+ (relax_avail && c == 'i')) {
break;
}
}
}
#else /* WIN32 */
int
-vshAskReedit(vshControl *ctl, const char *msg ATTRIBUTE_UNUSED)
+vshAskReedit(vshControl *ctl,
+ const char *msg ATTRIBUTE_UNUSED,
+ bool relax_avail ATTRIBUTE_UNUSED)
{
vshDebug(ctl, VSH_ERR_WARNING, "%s", _("This function is not "
"supported on WIN32 platform"));
/*
* virsh.h: a shell to exercise the libvirt API
*
- * Copyright (C) 2005, 2007-2014 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
int vshEditFile(vshControl *ctl, const char *filename);
char *vshEditReadBackFile(vshControl *ctl, const char *filename);
-int vshAskReedit(vshControl *ctl, const char *msg);
+int vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail);
int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
void *opaque);
double vshPrettyCapacity(unsigned long long val, const char **unit);