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

Some experiences and feedback about falcon command #70

Open
wildjcrt opened this issue Jul 28, 2019 · 2 comments
Open

Some experiences and feedback about falcon command #70

wildjcrt opened this issue Jul 28, 2019 · 2 comments

Comments

@wildjcrt
Copy link

This is an experience feedback.

I started to try falcon serve on MBP and I felt it quite annoyed me when I always typo as falcon server.
I then thought what if falcon command supports aliases like falcon server or falcon s.

In 5xruby after hack, next day after RubyConf Taiwan 2019, I started to try coding on subcommand aliases.

In the beginning, I code for falcon s as alias of falcon serve because it is shorter and similar to rails s.
Referece from rails/commands.rb, I wrote some codes blow.

require 'falcon/command'

aliases = {
  'server' => 'serve',
  's'  => 'serve',
  'sv' => 'supervisor',
  'v'  => 'virtual',
  'h'  => 'host'
}

command = ARGV.shift
command = aliases[command] || command

Falcon::Command.invoke command, ARGV

Later on, I discussed with @ioquatix and I got some of his considerations.

  1. We don't know if there will be a falcon server subcommand in the future.
  2. It would be better to show 'did you mean?' part first.

Next round, I tried to send PR for Samovar gem.
When I dived into Samovar::Nested#parse, I found falcon s --bind http://localhost:3000 will go into @default part.
In Falcon::Command::Top, the nested method set up default: 'serve'.
It means when falcon s --bind http://localhost:3000 fail, it should fallback to run falcon serve --bind http://localhost:3000 with input ['s', '--bind', 'http://localhost:3000']. And then it failed because there is also no s subcommand in falcon serve so the return is error message "Could not parse token "s" in:" with falcon serve help text.

@ioquatix and I had another discussion about how to parse subcommand.
I think it would be better to check if input.first =~ /^-.*/ and we can deal something when this situation happens.
Alternative way is that we should parse the whole command and run on a correct order.

For the first way, it would be tricky. It's more better to use begin…rescue…end in @default part instead.The problem is I don't like the code smell because there is a lot of elsif and then begin…rescue…end inside of it.

For the second way, the #parse method will become very complex and some command line features like -- might be broken.

This experience met a lot of different situation and I can't send any PR finally. Just raise issue to record it.

@ioquatix
Copy link
Member

Thanks for your feedback and I will consider how we can fix this issue.

@wildjcrt
Copy link
Author

Quick add my opinion.

I think falcon is quite good and I want more people to try it. falcon server or falcon s aliases would be easier for most of Rubyists (I believe so) to just start without looking at README.

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

No branches or pull requests

2 participants