]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix argument parsing for --boolean and --use-git-files 29/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 8 Oct 2016 19:15:33 +0000 (15:15 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 8 Oct 2016 19:15:33 +0000 (15:15 -0400)
bool('0') evaluates to True, so type=bool does not work as expected.
It is necessary to use a helper function which converts strings to
True/False as expected.

Also, fix parse_boolean().

mkosi

diff --git a/mkosi b/mkosi
index afbbbdb4664c165e93c74109e190abafb910653d..75ac1852dc153d95f2335707ccb75189a6b707b3 100755 (executable)
--- a/mkosi
+++ b/mkosi
@@ -1003,7 +1003,8 @@ def parse_args():
     group.add_argument('-t', "--format", dest='output_format', choices=OutputFormat.__members__, help='Output Format')
     group.add_argument('-o', "--output", help='Output image path', metavar='PATH')
     group.add_argument('-f', "--force", action='store_true', help='Remove existing image file before operation')
-    group.add_argument('-b', "--bootable", action='store_true', help='Make image bootable on EFI (only raw_gpt, raw_btrfs)')
+    group.add_argument('-b', "--bootable", type=parse_boolean, nargs='?', const=True,
+                       help='Make image bootable on EFI (only raw_gpt, raw_btrfs)')
     group.add_argument("--read-only", action='store_true', help='Make root volume read-only (only raw_btrfs, subvolume)')
     group.add_argument("--compress", action='store_true', help='Enable compression in file system (only raw_btrfs, subvolume)')
     group.add_argument("--xz", action='store_true', help='Compress resulting image with xz (only raw_gpt, raw_btrfs, implied on tar)')
@@ -1016,7 +1017,7 @@ def parse_args():
     group.add_argument("--build-script", help='Build script to run inside image', metavar='PATH')
     group.add_argument("--build-sources", help='Path for sources to build', metavar='PATH')
     group.add_argument("--build-package", action=PackageAction, dest='build_packages', help='Additional packages needed for build script', metavar='PACKAGE')
-    group.add_argument('--use-git-files', type=bool,
+    group.add_argument('--use-git-files', type=parse_boolean,
                        help='Ignore any files that git itself ignores (default: guess)')
     group.add_argument("--settings", dest='nspawn_settings', help='Add in .spawn settings file', metavar='PATH')
 
@@ -1130,7 +1131,7 @@ def parse_boolean(s):
     if s in {"0", "false", "no"}:
         return False
 
-    return KeyError("Unknown setting")
+    raise ValueError("invalid literal for bool(): {!r}".format(s))
 
 def process_setting(args, section, key, value):
     if section == "Distribution":