-
Notifications
You must be signed in to change notification settings - Fork 555
Add default
, as a shortcut for alias default
#106
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
Conversation
executable/FnmApp.re
Outdated
@@ -3,6 +3,7 @@ let version = Fnm.Fnm__Package.version; | |||
module Commands = { | |||
let use = (version, quiet) => Lwt_main.run(Use.run(~version, ~quiet)); | |||
let alias = (version, name) => Lwt_main.run(Alias.run(~name, ~version)); | |||
let default = (version, name) => Lwt_main.run(Alias.run(~name, ~version)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shorter way would've been to set ~name="default"
but that doesn't look or feel right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally understand your take on this, but considering how hard is it for a new contributor (and new Reason user) to understand Cmdliner, I think it's better to set the default
magic string here and not in the Cmdliner bloat. This module (Commands
) is easy to read and pretty much sums everything up.
And it's not that we don't have the magic default
string here, it is just written in the weird land of Cmdliner, where it's harder to follow on things 😜
The other approach was to remove the default
function completely because it is exactly like the alias command
, and use the const("default")
you have used into Commands.alias
.
However, I think your choice of making a new command looks much nicer. Every command exposes a function in the Commands
module. Cmdliner is just something we have to use in order to make good CLIs, but it's just an adapter 😄
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After much thinking and mulling in what you said, I agree that the magic string in the Commands
module is very suitable.
But having each Commands
expose a new command with its own function is really intuitive. It also means we can customize CLI helper comments and whatnot for each command without having to overlap, say, alias
and default
.
:D This is fun.
let sdocs = Manpage.s_common_options; | ||
|
||
let selectedVersion = { | ||
let doc = "The version to be aliased as default"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't believe you started learning Reason and Ocaml late 2018 from your given articles. There's a lot to take in, especially just trying to understand a library like lwt and cmdliner, on top of setting up the build system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I normally don't try to understand 100% of the things. This is why I use pesy
here instead of pure Dune, but I also used Dune in another project where I tried to learn native OCaml/Reason.
Lwt feels a lot like JS promises, and I read a lot about functional programming and these monadic interfaces for a couple of years. This is a very big thing to learn but the ppx_lwt
makes it easier, just like async await in JS
Cmdliner is very hard and I just read and copied from the docs until it worked! 😜 I read on the Reason Discord that there's a ppx_deriving_cmdliner
which is interesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah thanks for the quick summary. Reread the lwt docs and they clearly make sense now.
And I finally understand what ppx are now too. They're like decorators in JS, or method attributes in C#. LOL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of them are like decorators or method attributes, but they work at compile time, unlike JS (not sure about C# though) - including type errors, type inference and autocomplete! ❤️
This is totally my bad. The way to run them is by supplying the esy build
./feature_tests/run.sh _build/default/executable/FnmApp.exe |
executable/FnmApp.re
Outdated
@@ -3,6 +3,7 @@ let version = Fnm.Fnm__Package.version; | |||
module Commands = { | |||
let use = (version, quiet) => Lwt_main.run(Use.run(~version, ~quiet)); | |||
let alias = (version, name) => Lwt_main.run(Alias.run(~name, ~version)); | |||
let default = (version, name) => Lwt_main.run(Alias.run(~name, ~version)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally understand your take on this, but considering how hard is it for a new contributor (and new Reason user) to understand Cmdliner, I think it's better to set the default
magic string here and not in the Cmdliner bloat. This module (Commands
) is easy to read and pretty much sums everything up.
And it's not that we don't have the magic default
string here, it is just written in the weird land of Cmdliner, where it's harder to follow on things 😜
The other approach was to remove the default
function completely because it is exactly like the alias command
, and use the const("default")
you have used into Commands.alias
.
However, I think your choice of making a new command looks much nicer. Every command exposes a function in the Commands
module. Cmdliner is just something we have to use in order to make good CLIs, but it's just an adapter 😄
What do you think?
|
||
VERSIONS_INSTALLED=$(fnm ls) | ||
|
||
echo "$VERSIONS_INSTALLED" | grep 8.11.3 | grep oldie | ||
echo "$VERSIONS_INSTALLED" | grep 6.11.3 | grep older | ||
echo "$VERSIONS_INSTALLED" | grep 6.11.3 | grep default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yes
Thanks for this PR! I'm sure people will be happy with it 😄 |
Darn, if we use the magic string default, the |
I use Lines 122 to 125 in cd0cb1a
The linebreak doesn't bother me 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amazing! 🌮
Thanks 😄
default
, as a shortcut for alias default
Fixes #73
Hey Schniz, this is the draft PR for the default command. Is this something you still want?
How do I actually run your feature tests? Below are my attempts:
feature_tests/run.sh
=> "No binary supplied!"feature_tests/aliases/run.sh
=> "feature_tests/aliases/run.sh: Permission denied"