bsv init command.
This commit is contained in:
@@ -22,7 +22,9 @@ import sys
|
||||
from textwrap import dedent
|
||||
|
||||
from bsv import __version__
|
||||
from bsv.cli import get_error_console, init_consoles
|
||||
from bsv.command import init_commands
|
||||
from bsv.util import default_bsv_config_path
|
||||
|
||||
|
||||
def make_parser(
|
||||
@@ -31,10 +33,20 @@ def make_parser(
|
||||
) -> ArgumentParser:
|
||||
parent_parser = ArgumentParser(add_help=False)
|
||||
parent_parser.add_argument(
|
||||
"--repository",
|
||||
type = Path,
|
||||
"--color",
|
||||
default = "auto",
|
||||
choices = ("always", "auto", "never"),
|
||||
help = dedent("""
|
||||
Bsv repository path. Overides default paths and BSV_REPOSITORY environment variable.
|
||||
Force or disable colors, or auto-detect terminal support.
|
||||
""").strip(),
|
||||
)
|
||||
parent_parser.add_argument(
|
||||
"--config",
|
||||
default = default_bsv_config_path(),
|
||||
type = Path,
|
||||
dest = "config_path",
|
||||
help = dedent("""
|
||||
Bsv config path. Overrides default paths and BSV_CONFIG environment variable.
|
||||
""").strip(),
|
||||
)
|
||||
|
||||
@@ -68,16 +80,16 @@ def main(
|
||||
)
|
||||
arg_dict = vars(parser.parse_args(args or sys.argv[1:]))
|
||||
|
||||
repository_path: Path | None = arg_dict.pop("repository")
|
||||
if repository_path is None and "BSV_REPOSITORY" in os.environ:
|
||||
repository_path = Path(os.environ["BSV_REPOSITORY"])
|
||||
# else:
|
||||
# for path in get_config_dirs():
|
||||
# maybe_config_path = path / "config.toml"
|
||||
# if maybe_config_path.is_file():
|
||||
# config_path = maybe_config_path
|
||||
# break
|
||||
color = arg_dict.pop("color")
|
||||
init_consoles(color=color)
|
||||
|
||||
command = arg_dict.pop("command")
|
||||
|
||||
return command(repository_path=repository_path, **arg_dict)
|
||||
try:
|
||||
return command(**arg_dict)
|
||||
except Exception as err:
|
||||
get_error_console().print_exception()
|
||||
except KeyboardInterrupt:
|
||||
return 130
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user