Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid option for a command should give the help for that command instead of the general help #1146

Open
flip111 opened this issue Dec 24, 2023 · 2 comments

Comments

@flip111
Copy link
Contributor

flip111 commented Dec 24, 2023

» spago build --watch
Invalid option `--watch'

Usage: spago (COMMAND | (-v|--version))
  PureScript package manager and build tool

Available options:
  -h,--help                Show this help text
  -v,--version             Show the current version

Available commands:
  init                     Initialise a new project
  fetch                    Downloads all of the project's dependencies
  install                  Compile the project's dependencies
  uninstall                Remove dependencies from a package
  build                    Compile the project
  run                      Run the project
  test                     Test the project
  bundle                   Bundle the project in a single file
  sources                  List all the source paths (globs) for the
                           dependencies of the project
  repl                     Start a REPL
  publish                  Publish a package
  upgrade                  Upgrade to the latest package set, or to the latest
                           versions of Registry packages
  docs                     Generate docs for the project and its dependencies
  registry                 Commands to interact with the Registry
  ls                       List packages or dependencies
  graph                    Generate a graph of modules or dependencies

Expected the help for the build command instead

» spago build --help
Usage: spago build [--monochrome|--no-color] [--offline] [-q|--quiet]
                   [-v|--verbose] [--backend-args ARGS] [--ensure-ranges]
                   [--json-errors] [--output DIR] [--pedantic-packages] [--pure]
                   [--purs-args ARGS] [-p|--package PACKAGE] ([--verbose-stats]
                   | [--censor-stats]) [--strict]
  Compile the project

Available options:
  --monochrome,--no-color  Force logging without ANSI color escape sequences
  --offline                Do not attempt to use the network. Warning: this will
                           fail if you don't have the necessary dependencies
                           already cached
  -q,--quiet               Suppress all spago logging
  -v,--verbose             Enable additional debug logging, e.g. printing `purs`
                           commands
  --backend-args ARGS      Arguments to pass to the running script
  --ensure-ranges          Add version bounds for all the dependencies of the
                           selected project
  --json-errors            Output compiler warnings/errors as JSON
  --output DIR             The output directory for compiled files
  --pedantic-packages      Check for redundant or missing packages in the config
                           and fail the build if any
  --pure                   Use the package information from the current
                           lockfile, even if it is out of date
  --purs-args ARGS         Arguments to pass to purs compile. Wrap in quotes.
                           `--output` and `--json-errors` must be passed to
                           Spago directly.
  -p,--package PACKAGE     Select the local project to build
  --verbose-stats          Show counts for each warning type
  --censor-stats           Censor warning/error summary
  --strict                 Promotes project sources' warnings to errors
  -h,--help                Show this help text
@flip111
Copy link
Contributor Author

flip111 commented Dec 25, 2023

Is it an idea to upgrade to optparse 6 first? I can't reproduce this with an example project. Any idea what could be wrong?

module Main where

import Prelude

import Control.Alt ((<|>))
import Data.Array as Array
import Data.Generic.Rep (class Generic)
import Data.Show.Generic (genericShow)
import Data.List (intercalate)
import Effect (Effect)
import Effect.Class.Console (log)
import Options.Applicative
import Data.Maybe

data Sample
  = Hello String
  | Goodbye

derive instance sampleEq :: Eq Sample
derive instance genericSample :: Generic Sample _
instance showSample :: Show Sample where show = genericShow


hello :: Parser Sample
hello = map Hello $
  strOption
    ( long "greeting"
    <> metavar "TARGET"
    <> help "The greeting" )

sample :: Parser Sample
sample = subparser
       ( command "hello"
         (info hello
               (progDesc "Print greeting"))
      <> command "goodbye"
         (info (pure Goodbye)
               (progDesc "Say goodbye"))
       )
      <|> subparser
       ( command "bonjour"
         (info hello
               (progDesc "Print greeting"))
      <> command "au-revoir"
         (info (pure Goodbye)
               (progDesc "Say goodbye"))
      <> commandGroup "French commands:"
      <> hidden
       )

run :: Sample -> Effect Unit
run (Hello str) = log $ "Hello, " <> str
run Goodbye = log "Goodbye."

opts :: ParserInfo Sample
opts = info (sample <**> helper) idm

prefs :: ParserPrefs
prefs =
  let (ParserPrefs p) = defaultPrefs
  in  ParserPrefs $ p { prefShowHelpOnError = true }

main :: Effect Unit
main = customExecParser prefs opts >>= run

@f-f
Copy link
Member

f-f commented Dec 25, 2023

Upgrade to optparse 6 is blocked on #1129

That example parser is not very close to the one we use in Spago, we have different prefs, then there's a separate branch for the version flag, and then the command parser is calling hsubparser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants