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

Switch to optparse #980

Merged
merged 27 commits into from
Sep 27, 2023
Merged

Switch to optparse #980

merged 27 commits into from
Sep 27, 2023

Conversation

deemp
Copy link
Contributor

@deemp deemp commented Aug 1, 2023

@f-f, this PR addresses #977

Description of the change

I used optparse instead of argparse for building spaghetto CLI.

optparse supports completions for bash, zsh, fish.

My tools were purescript 0.15.10 and spago 0.93.9.

I followed the Developing instructions and built an executable in the spaghetto directory.

spago bundle -p spago-bin
cd bin
ln -s bundle.js spaghetto

Next, I manually tested completions

source <(./spaghetto --bash-completion-script ./spaghetto)
./spaghetto <TAB>
build     bundle    fetch     -h        --help    init      install   ls        publish   registry  repl      run       sources   test

Finally, I ran tests with

spago test

11/13 tests were successful.

Warning

  • I added metavars like ARGS in some places. They can be renamed/removed when necessary
  • As there were many flags, I may have made some typos

@deemp deemp mentioned this pull request Aug 2, 2023
spaghetto/bin/src/Flags.purs Outdated Show resolved Hide resolved
spaghetto/bin/src/Main.purs Outdated Show resolved Hide resolved

-- <* hsubparser (help "")
-- <* infoOption BuildInfo.currentSpagoVersion (?_)
-- ArgParser.flagInfo [ "--version" ] "Show the current version" BuildInfo.currentSpagoVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a spago --version flag to return the current version number, which is what the BuildInfo.currentSpagoVersion returns

Copy link
Contributor Author

@deemp deemp Aug 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use a command instead of a flag for printing the version.

459b17c

This command doesn't trigger printing the help message when prefShowHelpOnError is set to true.

I considered infoOption, but this option always fails. So, it prints both a version and a help message.

Copy link
Member

@f-f f-f Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need a flag for the version, rather than a command - this has come up before, see #608

I'd basically like to mirror the behaviour of purs:

$ purs --version
0.15.9

..so it would we great if we can avoid printing the help message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a --version flag. After spago bundle -p spago-bin:

$ bin/bundle.js --help
Usage: bundle.js ([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
...
$ bin/bundle.js --version
0.93.9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove the version command?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a --version flag

Looks great!

Should I remove the version command?

Yes please! We shouldn't add one unless it's necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 87ccdf6

spaghetto/bin/src/Optparse.purs Outdated Show resolved Hide resolved
spaghetto/bin/src/Main.purs Outdated Show resolved Hide resolved
@deemp deemp force-pushed the master branch 2 times, most recently from e4ff54c to bf02067 Compare August 11, 2023 17:28
@deemp
Copy link
Contributor Author

deemp commented Aug 15, 2023

@f-f, please, review

@deemp deemp requested a review from f-f August 15, 2023 17:41
@f-f
Copy link
Member

f-f commented Aug 28, 2023

@deemp I was on holiday and mostly offline, will have a look now

@f-f
Copy link
Member

f-f commented Sep 4, 2023

I'm sorting out CI so that we can merge - we still have the Haskell CI, so the tests for the new spago are not running at all yet

@f-f
Copy link
Member

f-f commented Sep 15, 2023

We have PureScript CI now! Could you rebase on the latest commit? I had to shuffle files around unfortunately, so it might be easier to just copy the patch to a new branch instead of trying to merge.

@f-f
Copy link
Member

f-f commented Sep 24, 2023

@deemp did you get any chance to look at this? anything I could help with?

@deemp
Copy link
Contributor Author

deemp commented Sep 24, 2023

@f-f, rebased and built 👌

@deemp
Copy link
Contributor Author

deemp commented Sep 24, 2023

@f-f, why does the -p flag work with the top-level command? Where is it defined?

run: ./bin/index.dev.js -p spago-bin

UPD: lol, it shouldn't work with the top-level command
https://github.com/purescript/spago/actions/runs/6285580917/job/17068112404#step:12:6
But the error is ignored in this workflow.

@f-f
Copy link
Member

f-f commented Sep 25, 2023

But the error is ignored in this workflow.

It's a good thing this fails explicitly now 🙂

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for rebasing @deemp! This looks great now - I left a few comments, mostly for things that slipped in the merge, but it's otherwise good to go

README.md Outdated Show resolved Hide resolved
spago.lock Outdated Show resolved Hide resolved
bin/src/Main.purs Outdated Show resolved Hide resolved
bin/src/Main.purs Outdated Show resolved Hide resolved
@f-f
Copy link
Member

f-f commented Sep 25, 2023

Ah, CI doesn't seem to be happy - we got a few of nonexistent options being used in the test (which should be easy to fix), but the bulk of the issue is - I think at least - the fact that we are using records to collect flags and arguments: this was ok when using argparse, because we used anyNotFlag. The new argument collection does not, so I suppose we should switch to applicative-do for collecting the flags first, and then collect any remaining arguments.

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a few tests failing - @deemp you can run tests locally with spago test to iterate more quickly (get the latest spago with npm install -g spago@next)

bin/src/Flags.purs Outdated Show resolved Hide resolved
@f-f
Copy link
Member

f-f commented Sep 27, 2023

@deemp amazing - feel free to comment out the remaining failing test, the -f flag was never implemented so it was passing just by accident 😄

Copy link
Member

@f-f f-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, this is finally green - merging.

Thanks a lot @deemp for the patch! 👏

@f-f f-f merged commit 32614da into purescript:master Sep 27, 2023
3 checks passed
@deemp
Copy link
Contributor Author

deemp commented Sep 27, 2023

@f-f, thanks for your guidance!

@f-f f-f mentioned this pull request Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants