0
0
mirror of https://github.com/tj/n.git synced 2024-11-21 18:48:57 +01:00

Allow options to come after commands

This commit is contained in:
John Gee 2019-08-20 20:50:16 +12:00
parent 488354dc9c
commit 9476384600
2 changed files with 35 additions and 12 deletions

View File

@ -7,7 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
<!-- markdownlint-disable MD024 -->
## [6.0.1] (date goes here)
## [6.0.1] (2019-08-20)
### Fixed
- allow options to come after commands, especially `nvh lsr --all`
## [6.0.0] (2019-08-16)
@ -200,6 +204,8 @@ Only minor functional changes, but technically could break scripts relying on sp
<!-- reference links for releases -->
[Unreleased]: https://github.com/tj/n/compare/master...develop
[6.0.1]: https://github.com/tj/n/compare/v6.0.0...v6.0.1
[6.0.0]: https://github.com/tj/n/compare/v5.0.2...v6.0.0
[5.0.2]: https://github.com/tj/n/compare/v5.0.1...v5.0.2
[5.0.1]: https://github.com/tj/n/compare/v5.0.0...v5.0.1
[5.0.0]: https://github.com/tj/n/compare/v4.1.0...v5.0.0

39
bin/n
View File

@ -40,7 +40,7 @@ function echo_red() {
# Setup and state
#
VERSION="6.0.1-0"
VERSION="6.0.1"
N_PREFIX="${N_PREFIX-/usr/local}"
N_PREFIX=${N_PREFIX%/}
@ -1144,22 +1144,39 @@ function show_diagnostics() {
# Handle arguments.
#
# First pass. Process the options so they can come before or after commands,
# particularly for `n lsr --all` and `n install --arch x686`
# which feel pretty natural.
unprocessed_args=()
while [[ $# -ne 0 ]]; do
case "$1" in
--all) N_MAX_REMOTE_MATCHES=32000 ;;
-V|--version) display_n_version ;;
-h|--help|help) display_help; exit ;;
-q|--quiet) set_quiet ;;
-d|--download) ACTIVATE=false ;;
--insecure) set_insecure ;;
--latest) display_remote_versions latest; exit ;;
--stable) display_remote_versions lts; exit ;; # [sic] old terminology
--lts) display_remote_versions lts; exit ;;
-a|--arch) shift; set_arch "$1";; # set arch and continue
exec) unprocessed_args=("$@"); break ;;
run|as|use) unprocessed_args=("$@"); break ;;
*) unprocessed_args+=( "$1" ) ;;
esac
shift
done
set -- "${unprocessed_args[@]}"
if test $# -eq 0; then
test -z "$(display_versions_paths)" && err_no_installed_print_help
menu_select_cache_versions
else
while test $# -ne 0; do
case "$1" in
--all) N_MAX_REMOTE_MATCHES=32000 ;;
-V|--version) display_n_version ;;
-h|--help|help) display_help; exit ;;
-q|--quiet) set_quiet ;;
-d|--download) ACTIVATE=false ;;
--insecure) set_insecure ;;
--latest) display_remote_versions latest; exit ;;
--stable) display_remote_versions lts; exit ;; # [sic] old terminology
--lts) display_remote_versions lts; exit ;;
-a|--arch) shift; set_arch "$1";; # set arch and continue
bin|which) display_bin_path_for_version "$2"; exit ;;
run|as|use) shift; run_with_version "$@"; exit ;;
exec) shift; exec_with_version "$@"; exit ;;