10000 Add `default`, as a shortcut for `alias default` by dangdennis · Pull Request #106 · Schniz/fnm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 5 commits into from
Jun 1, 2019

Conversation

dangdennis
Copy link
Contributor

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"

@@ -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));
Copy link
Contributor Author

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.

Copy link
Owner

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?

10000

Copy link
Contributor Author

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";
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 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.

Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Owner

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! ❤️

@dangdennis dangdennis marked this pull request as ready for review May 31, 2019 01:40
@Schniz
Copy link
Owner
Schniz commented May 31, 2019

How do I actually run your feature tests?

This is totally my bad. The way to run them is by supplying the fnm binary, which is like:

esy build
./feature_tests/run.sh _build/default/executable/FnmApp.exe

@@ -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));
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

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

oh yes

@Schniz Schniz added the PR: New Feature A new feature was added label May 31, 2019
@Schniz
Copy link
Owner
Schniz commented May 31, 2019

Thanks for this PR! I'm sure people will be happy with it 😄
Awesome work understanding how to work with Cmdliner, by the way! 🌮 🌵

@dangdennis
Copy link
Contributor Author

Darn, if we use the magic string default, the Commands.default breaks into a second line. Totally superfluous issue. Is this a prettier or eslint setting you set up somewhere?

@Schniz
Copy link
Owner
Schniz commented Jun 1, 2019

Is this a prettier or eslint setting you set up somewhere?

I use refmt which works like Prettier, or, actually, the other way around 😉

fnm/package.json

Lines 122 to 125 in cd0cb1a

"*.re": [
"esy refmt --in-place",
"git add"
],

The linebreak doesn't bother me 😄

Copy link
Owner
@Schniz Schniz left a comment

Choose a reason for hiding this comment

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

amazing! 🌮
Thanks 😄

@Schniz Schniz changed the title Feat default alias Add default, as a shortcut for alias default Jun 1, 2019
@Schniz Schniz merged commit 430541a into Schniz:master Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: New Feature A new feature was added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature requests / wishlist
2 participants
0