diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-11 22:39:20 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-11 22:39:20 +0300 |
| commit | b01d9b0ec378740589d6473f4b6b9d63ca673f72 (patch) | |
| tree | eae92dba11514ca3159a68fbd964fcb77b958c25 /src | |
| parent | 44d3f7a689751633f8ac5f06b4ba0be8c056bb42 (diff) | |
Make main CLI state explicit for task 8m0
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/action.source.sh | 19 | ||||
| -rw-r--r-- | src/lib/config.cli.source.sh | 25 | ||||
| -rwxr-xr-x | src/shuriken.sh | 17 |
3 files changed, 35 insertions, 26 deletions
diff --git a/src/lib/action.source.sh b/src/lib/action.source.sh index 193aa4b..f1103a6 100644 --- a/src/lib/action.source.sh +++ b/src/lib/action.source.sh @@ -1,7 +1,8 @@ run_simple_action() { - case "$action" in + case "$SHURIKEN_CLI_ACTION" in --version) - if [[ -n "$config_file" || "$has_config_overrides" = 'yes' \ + if [[ -n "$SHURIKEN_CLI_CONFIG_FILE" \ + || "$SHURIKEN_CLI_HAS_CONFIG_OVERRIDES" = 'yes' \ || "$SHURIKEN_FORCE_GENERATE" = yes ]]; then usage exit 1 @@ -10,7 +11,8 @@ run_simple_action() { printf 'This is Shuriken Version %s\n' "$VERSION" ;; --init) - if [[ -n "$config_file" || "$has_config_overrides" = 'yes' \ + if [[ -n "$SHURIKEN_CLI_CONFIG_FILE" \ + || "$SHURIKEN_CLI_HAS_CONFIG_OVERRIDES" = 'yes' \ || "$SHURIKEN_FORCE_GENERATE" = yes ]]; then usage exit 1 @@ -40,7 +42,7 @@ load_configured_action() { log_configured_action() { local -r rc_file="$1"; shift - if [ "$action" = --print-config ]; then + if [ "$SHURIKEN_CLI_ACTION" = --print-config ]; then return fi @@ -60,16 +62,17 @@ log_configured_action() { run_configured_action() { local rc_file - if [[ "$SHURIKEN_FORCE_GENERATE" = yes && "$action" != --generate ]]; then + if [[ "$SHURIKEN_FORCE_GENERATE" = yes \ + && "$SHURIKEN_CLI_ACTION" != --generate ]]; then usage exit 1 fi - rc_file="$(resolve_config_file "$config_file")" + rc_file="$(resolve_config_file "$SHURIKEN_CLI_CONFIG_FILE")" load_configured_action "$rc_file" log_configured_action "$rc_file" - case "$action" in + case "$SHURIKEN_CLI_ACTION" in --clean) if [ -d "$DIST_DIR" ]; then log_info "Cleaning $DIST_DIR" @@ -102,7 +105,7 @@ run_configured_action() { } run_action() { - case "$action" in + case "$SHURIKEN_CLI_ACTION" in --version|--init) run_simple_action ;; diff --git a/src/lib/config.cli.source.sh b/src/lib/config.cli.source.sh index 1df4b84..90e4998 100644 --- a/src/lib/config.cli.source.sh +++ b/src/lib/config.cli.source.sh @@ -14,8 +14,9 @@ option_value() { apply_cli_override() { local -r config_target="$1"; shift - if [[ -v "cli_overrides[$config_target]" ]]; then - printf -v "$config_target" '%s' "${cli_overrides[$config_target]}" + if [[ -v "SHURIKEN_CLI_OVERRIDES[$config_target]" ]]; then + printf -v "$config_target" '%s' \ + "${SHURIKEN_CLI_OVERRIDES[$config_target]}" fi } @@ -26,8 +27,8 @@ apply_cli_overrides() { apply_cli_override "$config_target" done - if (( ${#cli_sync_destinations[@]} > 0 )); then - SYNC_DESTINATIONS=("${cli_sync_destinations[@]}") + if (( ${#SHURIKEN_CLI_SYNC_DESTINATIONS[@]} > 0 )); then + SYNC_DESTINATIONS=("${SHURIKEN_CLI_SYNC_DESTINATIONS[@]}") fi } @@ -37,15 +38,15 @@ set_cli_option_value() { local config_target if [ "$option" = --sync-destination ]; then - cli_sync_destinations+=("$value") - has_config_overrides='yes' + SHURIKEN_CLI_SYNC_DESTINATIONS+=("$value") + SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='yes' return fi config_target="${CLI_OPTION_CONFIG_TARGET[$option]:-}" if [ -n "$config_target" ]; then - cli_overrides["$config_target"]="$value" - has_config_overrides='yes' + SHURIKEN_CLI_OVERRIDES["$config_target"]="$value" + SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='yes' return fi @@ -59,8 +60,8 @@ set_cli_constant_option() { config_target="${CLI_OPTION_CONFIG_TARGET[$option]:-}" if [ -n "$config_target" ]; then - cli_overrides["$config_target"]="$value" - has_config_overrides='yes' + SHURIKEN_CLI_OVERRIDES["$config_target"]="$value" + SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='yes' return fi @@ -70,12 +71,12 @@ set_cli_constant_option() { set_cli_action() { local -r selected_action="$1"; shift - if [ -n "$action" ]; then + if [ -n "$SHURIKEN_CLI_ACTION" ]; then usage exit 1 fi - action="$selected_action" + SHURIKEN_CLI_ACTION="$selected_action" } parse_cli_arguments() { diff --git a/src/shuriken.sh b/src/shuriken.sh index 6edb7a6..448e66b 100755 --- a/src/shuriken.sh +++ b/src/shuriken.sh @@ -16,6 +16,11 @@ SHURIKEN_OUTPUT_MODE="${SHURIKEN_OUTPUT_MODE:-normal}" SHURIKEN_ACTIVE_GENERATION_PID='' SHURIKEN_FORCE_GENERATE="${SHURIKEN_FORCE_GENERATE:-no}" SHURIKEN_CURRENT_DATE_TEXT='' +SHURIKEN_CLI_ACTION='' +SHURIKEN_CLI_CONFIG_FILE='' +SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='no' +declare -A SHURIKEN_CLI_OVERRIDES=() +declare -a SHURIKEN_CLI_SYNC_DESTINATIONS=() declare -ra CLI_CONFIG_OVERRIDE_TARGETS=( INCOMING_DIR @@ -65,7 +70,7 @@ declare -Ar CLI_OPTION_KIND=( [--print-config]=action ) declare -Ar CLI_OPTION_TARGET=( - [--config]=config_file + [--config]=SHURIKEN_CLI_CONFIG_FILE [--verbose]=SHURIKEN_OUTPUT_MODE [--quiet]=SHURIKEN_OUTPUT_MODE [--force]=SHURIKEN_FORCE_GENERATE @@ -138,11 +143,11 @@ source "$SHURIKEN_SOURCE_DIR/lib/action.source.sh" # SHURIKEN_LIB_SOURCES_END main() { - local action='' - local config_file='' - local has_config_overrides='no' - local -A cli_overrides=() - local -a cli_sync_destinations=() + SHURIKEN_CLI_ACTION='' + SHURIKEN_CLI_CONFIG_FILE='' + SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='no' + SHURIKEN_CLI_OVERRIDES=() + SHURIKEN_CLI_SYNC_DESTINATIONS=() if (( $# == 0 )); then usage |
