forked from siemens/efibootguard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bg_setenv/bg_printenv: bash and zsh completion
With the plethora of new command-line options, it is starting to get difficult to remember them all. This commit introduces shell completions for bash and zsh for the convenience of the user. Instead of writing the completion files by hand (a tedious task), the files are generated automatically from a Python spec using shtab [1]. The latter is stored as a git submodule, making it possible to generate the completion files at build time without having to install shtab (which is typically not available in package managers). [1] https://github.com/iterative/shtab Signed-off-by: Michael Adler <[email protected]> Signed-off-by: Jan Kiszka <[email protected]>
- Loading branch information
1 parent
e499d40
commit 9cd9e90
Showing
15 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "tests/fff"] | ||
path = tests/fff | ||
url = https://github.com/meekrosoft/fff | ||
[submodule "completion/shtab"] | ||
path = completion/shtab | ||
url = https://github.com/iterative/shtab.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!bg_printenv | ||
!bg_setenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# Copyright (c) Siemens AG, 2021 | ||
# | ||
# Authors: | ||
# Michael Adler <[email protected]> | ||
# | ||
# This work is licensed under the terms of the GNU GPL, version 2. See | ||
# the COPYING file in the top-level directory. | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import argparse | ||
|
||
from .common import add_common_opts | ||
|
||
|
||
def bg_printenv(): | ||
parser = argparse.ArgumentParser(prog="bg_printenv", add_help=False) | ||
add_common_opts(parser) | ||
parser.add_argument("-c", "--current", action="store_true", help="Only print values from the current environment") | ||
parser.add_argument( | ||
"-o", | ||
"--output", | ||
choices=["in_progress", "revision", "kernel", "kernelargs", "watchdog_timeout", "ustate", "user"], | ||
help="Comma-separated list of fields which are printed", | ||
) | ||
parser.add_argument("-r", "--raw", action="store_true", help="Raw output mode") | ||
parser.add_argument("--usage", action="store_true", help="Give a short usage message") | ||
return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../common.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# | ||
# Copyright (c) Siemens AG, 2021 | ||
# | ||
# Authors: | ||
# Michael Adler <[email protected]> | ||
# | ||
# This work is licensed under the terms of the GNU GPL, version 2. See | ||
# the COPYING file in the top-level directory. | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import argparse | ||
|
||
from .common import add_common_opts | ||
|
||
|
||
def bg_setenv(): | ||
parser = argparse.ArgumentParser(prog="bg_setenv", add_help=False) | ||
add_common_opts(parser) | ||
parser.add_argument("-P", "--preserve", action="store_true", help="Preserve existing entries") | ||
parser.add_argument("-k", "--kernel", metavar="KERNEL", help="Set kernel to load") | ||
parser.add_argument("-a", "--args", metavar="KERNEL_ARGS", help="Set kernel arguments") | ||
parser.add_argument("-r", "--revision", metavar="REVISION", help="Set revision value") | ||
parser.add_argument( | ||
"-s", | ||
"--ustate", | ||
choices=["OK", "INSTALLED", "TESTING", "FAILED", "UNKNOWN"], | ||
metavar="USTATE", | ||
help="Set update status for environment", | ||
) | ||
parser.add_argument("-w", "--watchdog", metavar="WATCHDOG_TIMEOUT", help="Watchdog timeout in seconds") | ||
parser.add_argument("-c", "--confirm", action="store_true", help="Confirm working environment") | ||
parser.add_argument("-u", "--update", action="store_true", help="Automatically update oldest revision") | ||
parser.add_argument( | ||
"-x", | ||
"--uservar", | ||
metavar="KEY=VAL", | ||
help="Set user-defined string variable. For setting multiple variables, use this option multiple times.", | ||
) | ||
parser.add_argument( | ||
"-i", | ||
"--in_progress", | ||
metavar="IN_PROGRESS", | ||
choices=["0", "1"], | ||
help="Set in_progress variable to simulate a running update process.", | ||
) | ||
return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../common.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# | ||
# Copyright (c) Siemens AG, 2021 | ||
# | ||
# Authors: | ||
# Michael Adler <[email protected]> | ||
# | ||
# This work is licensed under the terms of the GNU GPL, version 2. See | ||
# the COPYING file in the top-level directory. | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
import shtab | ||
|
||
|
||
def add_common_opts(parser): | ||
parser.add_argument( | ||
"-f", "--filepath", metavar="ENVFILE", help="Environment to use. Expects a file name, usually called BGENV.DAT." | ||
).complete = shtab.FILE | ||
parser.add_argument("-p", "--part", metavar="ENV_PART", type=int, help="Set environment partition to update") | ||
parser.add_argument("-v", "--verbose", action="store_true", help="Be verbose") | ||
parser.add_argument("-V", "--version", action="store_true", help="Print version") | ||
# there is a bug in shtab which currently prohibits "-?" | ||
parser.add_argument("--help", action="store_true", help="Show help") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters