-
Notifications
You must be signed in to change notification settings - Fork 241
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
Discussion: CLI UI refactoring #343
Conversation
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.
Wow, looks great, I've not seen or used Clamp before.. I used sub in the past to organise subcommands, but this seems more up to date and easier to integrate.
I like the how Clamp::Command
can associate ENV vars with flags and the fact the gem has no other dependencies.
I'm all for these changes - I agree that bin/lolcommits has always been a bit of a dumping ground. I added a couple of inline comments, but here are a few more questions;
- Do we still need methadone after switching to Clamp? Clamp deals with opts/flags/sub commands and ENVs' - are we keeping Methadone around for testing/logging convenience?
- Would it make sense to move all the Clamp::Command classes to their own files within
lib/lolcommits/cli
?
I'm still working away on plugin extraction - got a bit sidetracked basically rewriting the Twitter plugin from scratch.. and the arrival of a baby - but should be back on track soon.
@@ -8,6 +8,10 @@ Feature: Basic UI functionality | |||
Then the exit status should be 0 | |||
And the banner should be present | |||
|
|||
Scenario: Help should format nicely on a 80x24 terminal | |||
When I get help for "lolcommits" | |||
Then the output should not contain any lines longer than 80 |
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.
👍
lib/lolcommits/cli/ui.rb
Outdated
class EnableCommand < Clamp::Command | ||
def execute | ||
# TODO: rationalize how to pass options to Installation.enable | ||
# previous version relied on all flags being global (yikes) |
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 options to Installation.do_enable(options)
end up just being a string, they are only used to populate the hook script with some default capture_args here ... so maybe you can get them from ARGV
directly?
Tests seems to be failing due to some Rubocop issues and some syntax errors; https://travis-ci.org/mroth/lolcommits/jobs/232434535 (in lib/lolcommits/cli/ui.rb) |
Also should mention - I don't think its too important to maintain exact parity or arg format and names on every command - EXCEPT the capture command - which lives in many git hooks around the world..... When I refactored to fully use Methadone (ditching Choice) I wasn't afraid to change a few option names where it made sense. -- tho obviously the wiki/README would need updating 📖 |
After this change Methadone is only adding the CLILogging. We could factor this out and use our own logger or a different gem, but I'd like to keep that separate. Another thing to consider that I alluded to in my longer notes is that right now I believe the logging is sprinkled across the files, so we need to figure out the import situation a little bit.
Absolutely. The feature tests could be broken up this way too. For the initial spike I wanted to leave it in a single file as it made it easier to see where the duplication was, would want to take a few structural passes on it to try to DRY things up.
The core change is that
I know! commented on the Instagram photo -- so awesome. 👶 ...Is he writing Ruby yet? He can have commit rights as soon as he can type. |
this also moves Methadone::CLILogging out of global scope, which will likely break some things — fixed a few but will have more to grab once tests are running.
No attempt to run and validate these yet (changes are expected!), just a quick cut and paste job, but starting to show there is value in this, but also just how much work it will be!
quick pass, this should let us eyeball in test errors what still remains to be implemented and what has been broken
somehow this didn’t exist before? strange
Clamp flags are only inherited with anonymous subclass block syntax for subcommands, so instead need to put them in our wrapper class (knew it would come in handy!). Some CLI managers have a separate concept for a global flag that exists between invocation ARGV[0] and the subcommand syntax wise, but Clamp does not, so keep things simple. In addition, need to make sure we pass the test mode flag on everywhere we instantiate the Configuration class. This is suggesting we can handle this instantiation once globally somewhere, but need to think about refactoring that.
Since we are not using methadone for CLI parsing, don’t need its custom Aruba matcher steps. Turns out we were barely using them, and they don’t add enough to even recreate them versus just having opaque steps.
in new CLI, we don’t check for fatals when just running the basic command, since we want to display the help screen first.
should make some tests pass, but also expose some new bugs
not strictly needed for enable, but want to make sure we verify there because next likely step afterwards an enable will be an automatically triggered capture
plugin name should be Optional. Also add some VCS fatals checks.
this seems perhaps outside of core functionality of lolcommits, but as it is already there, so… I guess it is fun.
This should really be refactored out, but out of scope for this UI related PR, so marking for future.
The refactoring fixed a bug where enable didn’t work in a subdir, not that it does, fix the test condition that was improperly passing
Given the pains of maintenance usually result from external gems, if we can build our own simple logger, I'd prefer that (and ditch Methadone)
Sounds like a plan 👍 for backwards compatibility - I think we definitely need to continue supporting the
No Ruby just yet, but we've watched some RailsConf 2017 talks together already. He's had me up since 4AM this morning 😪 ! |
Makes sense to me. Could probably get most of what we need just by wrapping the standard Logger in Ruby stdlib. Do you think this would need to be part of this change, or a separate refactoring?
Didn't seem possible to do this easily via Clamp directly, but I put in a hack in 8a8c7c1 that I think handles it with a bit of brute force simplicity. :-) |
At this point, I've gotten it to the point where there are only two things remaining to all tests passing:
(Things are certainly workable enough now that this branch can be used for messing around and seeing how the UI of the commands "feels" and refining it and the name choices.) |
WIP SAMPLE CODE -- BROKEN DO NOT MERGE.
For discussion with @matthutchinson (at your convenience! a slow burn on this makes sense, no rush), beginning of a patch that refactors the CLI UI of lolcommits to be significantly more modular and easy to understand, byusing subcommands. Previously, there was only one lolcommits "command", and actions were emulated by a bunch of logic around now different option flags were treated. All flags were global so it was unclear what options were compatible with which actions, etc. Now, with subcommands:
Since we haven't hit v1.0 yet, we have a chance to make breaking changes to the UI. So on the "road to 1.0" along with the plugin extraction, I'd like to bring this up for consideration.
The
bin/lolcommits
was one of the messiest areas of the code, so this also starts on a refactor and cleanup (but trying to confine to the UI changes for now).We get a lot for free from using Clamp here, such as automatic handling of environment variables linked to option flags (with validation of content type). This removes quite a bit of boilerplate from the code and I believe makes things more reliable.
Main purpose of this PR at present is to have a discussion about the UI tradeoffs here.
If we decide we do want to go down this path, some other things we'll need to discuss:
enable
. Previously this took advantage of the side effect that all flags were global. While we could certainly duplicate the flags for enable, I think it's worth considering a different approach -- I'm not convinced putting UI flags in the stub is a good idea. (At a minimum, we'd probably want to change to installing these options as environment variable sets in the stub instead.)change_dir_to_root_or_repo!
. I think there might be a better way to accomplish this, but need to look into what the original impetus was. (Either way, it should probably be moved into a library and out of the CLI logic).Methadone::CLILogging
across the application. We can preserve this dependency for logging but perhaps worth thinking about whether something else fits the needs better. In any event, we also would need to refactor the CLILogging imports better, since previously it was Included into global scope in the main bin and all the places we called it sprinkled across the code seem to just rely on it being present.P.S. Out of scope for this initial PR, but it makes me realize that it may be worthwhile longer term to refactor and rationalize the API of lolcommits outside of the command line binary. It should probably be possible to move all the logic into the library such that the gem could be used from within Ruby with signature such as
Lolcommits.action_name(path, options)
taking a string and a defined Options struct, and the CLI code would simply then handle constructing the correct Options and displaying errors that are bubbled back up. This is obviously a fairly large project however.