
export def show_titles []: nothing -> nothing {
  if (detect_claude_code) { return false }
  if ($env.PROVISIONING_NO_TITLES? | default false) { return }
  if ($env.PROVISIONING_OUT | is-not-empty) { return }
  _print $"(_ansi blue_bold)(open -r ($env.PROVISIONING_RESOURCES | path join "ascii.txt"))(_ansi reset)"
}
export def use_titles [ ]: nothing -> bool {
  if ($env.PROVISIONING_NO_TITLES? | default false) { return }
  if ($env.PROVISIONING_NO_TERMINAL? | default false) { return false }
  if ($env.PROVISIONING_ARGS? | str contains "-h" ) { return false }
  if ($env.PROVISIONING_ARGS? | str contains "--notitles" ) { return false }
  if ($env.PROVISIONING_ARGS? | str contains "query") and ($env.PROVISIONING_ARGS? | str contains "-o" ) { return false }
  true
}
export def provisioning_init [
  helpinfo: bool
  module: string
  args: list<string>  # Other options, use help to get info
]: nothing -> nothing {
  if (use_titles) { show_titles }
  if $helpinfo != null and $helpinfo {
    let cmd_line: list<string> = if ($args| length) == 0 {
        $args | str join " "
    } else {
        $env.PROVISIONING_ARGS? | default ""
    }
    let cmd_args: list<string> = ($cmd_line | str replace "--helpinfo" "" |
       str replace "-h"  "" | str replace $module "" | str trim | split  row " "
    )
    if ($cmd_args | length) > 0 {
        # _print $"---($module)-- ($env.PROVISIONING_NAME) -mod '($module)' ($cmd_args) help"
        ^$"($env.PROVISIONING_NAME)" "-mod" $"($module | str replace ' ' '|')" ...$cmd_args help
        # let str_mod_0 = ($cmd_args | get -o 0 | default "")
        # let str_mod_1 = ($cmd_args | get -o 1 | default "")
        # if $str_mod_1 != "" {
        #     let final_args = ($cmd_args | drop nth 0 1)
        #     _print $"---($module)-- ($env.PROVISIONING_NAME) -mod '($str_mod_0) ($str_mod_1)' ($cmd_args | drop nth 0) help"
        #     ^$"($env.PROVISIONING_NAME)" "-mod" $"'($str_mod_0) ($str_mod_1)'" ...$final_args help
        # } else {
        #     let final_args = ($cmd_args | drop nth 0)
        #     _print $"---($module)-- ($env.PROVISIONING_NAME) -mod ($str_mod_0) ($cmd_args | drop nth 0) help"
        #     ^$"($env.PROVISIONING_NAME)" "-mod" ($str_mod_0) ...$final_args help
        # }
    } else {
      ^$"($env.PROVISIONING_NAME)" help
    }
    exit 0
  }
}
