verbose option
This commit is contained in:
parent
5864a69f1b
commit
35f3197142
|
|
@ -7,7 +7,7 @@ _lxcd_completion() {
|
||||||
local commands="create clone rename enter list delete add stop start restart"
|
local commands="create clone rename enter list delete add stop start restart"
|
||||||
|
|
||||||
if [ $cword -eq 1 ]; then
|
if [ $cword -eq 1 ]; then
|
||||||
COMPREPLY=($(compgen -W "${commands}" -- "$cur"))
|
COMPREPLY=($(compgen -W "-v --verbose ${commands}" -- "$cur"))
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
16
lxcd.py
16
lxcd.py
|
|
@ -49,6 +49,8 @@ def detect_locale():
|
||||||
return os.environ.get("LANG", "en_US.UTF-8")
|
return os.environ.get("LANG", "en_US.UTF-8")
|
||||||
|
|
||||||
|
|
||||||
|
VERBOSE = False
|
||||||
|
|
||||||
def lxc_prefix():
|
def lxc_prefix():
|
||||||
"""Return ['sudo'] if the user isn't root and isn't in the lxd group."""
|
"""Return ['sudo'] if the user isn't root and isn't in the lxd group."""
|
||||||
if os.getuid() == 0:
|
if os.getuid() == 0:
|
||||||
|
|
@ -70,11 +72,17 @@ def run_cmd(cmd, check=True):
|
||||||
|
|
||||||
def lxc_run(args, check=True):
|
def lxc_run(args, check=True):
|
||||||
"""Run an lxc command via run_cmd, auto-adding sudo if needed."""
|
"""Run an lxc command via run_cmd, auto-adding sudo if needed."""
|
||||||
return run_cmd([*lxc_prefix(), "lxc", *args], check=check)
|
cmd = [*lxc_prefix(), "lxc", *args]
|
||||||
|
if VERBOSE:
|
||||||
|
print(f"+ {' '.join(cmd)}", file=sys.stderr)
|
||||||
|
return run_cmd(cmd, check=check)
|
||||||
|
|
||||||
def lxc_subprocess(args, **kwargs):
|
def lxc_subprocess(args, **kwargs):
|
||||||
"""Run an lxc command via subprocess.run, auto-adding sudo if needed."""
|
"""Run an lxc command via subprocess.run, auto-adding sudo if needed."""
|
||||||
return subprocess.run([*lxc_prefix(), "lxc", *args], **kwargs)
|
cmd = [*lxc_prefix(), "lxc", *args]
|
||||||
|
if VERBOSE:
|
||||||
|
print(f"+ {' '.join(cmd)}", file=sys.stderr)
|
||||||
|
return subprocess.run(cmd, **kwargs)
|
||||||
|
|
||||||
def handle_list(args):
|
def handle_list(args):
|
||||||
print("Fetching lxcd container environments...")
|
print("Fetching lxcd container environments...")
|
||||||
|
|
@ -518,6 +526,7 @@ def handle_rename(args):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="lxcd: A Distrobox-like wrapper for LXD (Sudo Optimized)")
|
parser = argparse.ArgumentParser(description="lxcd: A Distrobox-like wrapper for LXD (Sudo Optimized)")
|
||||||
|
parser.add_argument("-v", "--verbose", action="store_true", help="Show verbose command output")
|
||||||
subparsers = parser.add_subparsers(dest="command", required=True)
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||||
|
|
||||||
# Create command
|
# Create command
|
||||||
|
|
@ -578,6 +587,9 @@ def main():
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
global VERBOSE
|
||||||
|
VERBOSE = args.verbose
|
||||||
|
|
||||||
if args.command == "create":
|
if args.command == "create":
|
||||||
handle_create(args)
|
handle_create(args)
|
||||||
elif args.command == "clone":
|
elif args.command == "clone":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue