Be more helpful to newcomers.

The error output when the bootstrapper is called without arguments or
with -h is lacking. Try to improve it.

Tweak the output when called without arguments when an installation is
found as well, in the same spirit.

Finally, change the print_usage() to a print_help() when no command is
given, to get additional context.

Fixes: #108

Signed-off-by: Marti Bolivar <marti@foundries.io>
This commit is contained in:
Marti Bolivar 2018-11-15 22:08:16 -07:00 committed by Carles Cufí
parent 47b328a05e
commit ab4ffcc51d
2 changed files with 38 additions and 14 deletions

View File

@ -123,7 +123,8 @@ def init(argv):
formatter_class=argparse.RawDescriptionHelpFormatter,
description=
'''
Initializes a Zephyr installation.
Initializes a Zephyr installation. Use "west clone" afterwards to fetch the
sources.
In more detail, does the following:
@ -182,7 +183,7 @@ to handle any resetting yourself.
installation to update the manifest or west URL/revision''')
init_parser.add_argument(
'directory', nargs='?',
'directory', nargs='?', default=None,
help='''Directory to initialize West in. Missing directories will be
created automatically. (default: current directory)''')
@ -247,7 +248,8 @@ def bootstrap(args):
with open(os.path.join(directory, WEST_DIR, WEST_MARKER), 'w') as f:
hide_file(f.name)
print('=== West initialized ===')
print('=== West initialized. Now run "west clone" in {}. ==='.
format(directory))
def reinit(config_path, args):
@ -355,21 +357,41 @@ def append_to_pythonpath(directory):
def wrap(argv):
printing_version = False
printing_help_only = False
if argv and argv[0] in ('-V', '--version'):
print('West bootstrapper version: v{} ({})'.format(version.__version__,
os.path.dirname(__file__)))
printing_version = True
if argv:
if argv[0] in ('-V', '--version'):
print('West bootstrapper version: v{} ({})'.
format(version.__version__, os.path.dirname(__file__)))
printing_version = True
elif len(argv) == 1 and argv[0] in ('-h', '--help'):
# This only matters if we're called outside of an
# installation directory. We delegate to the main help if
# called from within one, because it includes a list of
# available commands, etc.
printing_help_only = True
start = os.getcwd()
try:
topdir = west_topdir()
topdir = west_topdir(start)
except WestNotFound:
if printing_version:
sys.exit(0) # run outside of an installation directory
elif printing_help_only:
# We call print multiple times here and below instead of using
# \n to be newline agnostic.
print('To set up a Zephyr installation here, run "west init".')
print('Run "west init -h" for additional information.')
sys.exit(0)
else:
sys.exit('Error: not a Zephyr directory (or any parent): {}\n'
'Use "west init" to install Zephyr here'
.format(os.getcwd()))
print('Error: "{}" is not a Zephyr installation directory.'.
format(start), file=sys.stderr)
print('Things to try:', file=sys.stderr)
print(' - Run "west init" to set up an installation here.',
file=sys.stderr)
print(' - Run "west init -h" for additional information.',
file=sys.stderr)
sys.exit(1)
west_git_repo = os.path.join(topdir, WEST_DIR, WEST)
if printing_version:

View File

@ -25,7 +25,7 @@ from west.commands.project import List, Clone, Fetch, Pull, Rebase, Branch, \
Checkout, Diff, Status, Update, ForAll, \
WestUpdated
from west.manifest import Manifest
from west.util import quote_sh_list, in_multirepo_install
from west.util import quote_sh_list, in_multirepo_install, west_dir
IN_MULTIREPO_INSTALL = in_multirepo_install(__file__)
@ -191,8 +191,10 @@ def parse_args(argv):
set_zephyr_base(args)
if 'handler' not in args:
log.err('you must specify a command', fatal=True)
west_parser.print_usage(file=sys.stderr)
log.err('west installation found (in {}), but no command given'.
format(west_dir()),
fatal=True)
west_parser.print_help(file=sys.stderr)
sys.exit(1)
return args, unknown