diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-23 01:34:03 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-06-23 01:34:03 +0000 |
commit | af5c9d95d0b06b1148cce53366adc8acc93dd43a (patch) | |
tree | 8e95f1aa13bac0abefbb02fe2a37fedb03e99feb | |
parent | 7a76c3555af9fb7f56327397ae2876bd684a95f0 (diff) | |
parent | 55d72833d8028d4ea52fd2cafdfd7381238b0479 (diff) | |
download | bundler-af5c9d95d0b06b1148cce53366adc8acc93dd43a.tar.gz |
Auto merge of #5725 - bundler:seg-default-command, r=indirect
Default to printing a help message when `bundle` is run without arguments on 2.0
### What was the end-user problem that led to this PR?
The problem was that users unfamiliar with Bundler would run `bundle` and either install gems (if in a directory with a gemfile), or else get the error `Could not locate Gemfile`. You'd need to know to run `bundle help` or `bundle -h` to get the man page, and even that could be overwhelming (not to mention turfing you into a pager).
### Was was your diagnosis of the problem?
My diagnosis was that we ought to print some form of help when the bare `bundle` command is run, rather than defaulting to running `bundle install`.
This work was prompted by https://trello.com/c/OpuOdTZl/112-print-help-when-bundle-is-run-without-arguments, and is an improvement (rather than a straight port) on https://github.com/bundler/bundler/pull/3831.
### What is your fix for the problem, implemented in this PR?
My fix was to print the following help output when the CLI is invoked without arguments, contingent upon a feature flag.
```
Bundler version 1.15.1
Commands:
bundle add GEM VERSION # Add gem to Gemfile and run bundle install
bundle binstubs GEM [OPTIONS] # Install the binstubs of the listed gem
bundle check [OPTIONS] # Checks if the dependencies listed in Gemfile are satisfied by currently installed gems
bundle clean [OPTIONS] # Cleans up unused gems in your bundler directory
bundle config NAME [VALUE] # retrieve or set a configuration value
bundle console [GROUP] # Opens an IRB session with the bundle pre-loaded
bundle doctor [OPTIONS] # Checks the bundle for common problems
bundle env # Print information about the environment Bundler is running under
bundle exec [OPTIONS] # Run the command in context of the bundle
bundle gem GEM [OPTIONS] # Creates a skeleton for creating a rubygem
bundle help [COMMAND] # Describe available commands or one specific command
bundle help [COMMAND] # Describe subcommands or one specific subcommand
bundle info GEM [OPTIONS] # Show information for the given gem
bundle init [OPTIONS] # Generates a Gemfile into the current working directory
bundle inject GEM VERSION # Add the named gem, with version requirements, to the resolved Gemfile
bundle install PLUGINS # Install the plugin from the source
bundle install [OPTIONS] # Install the current environment to the system
bundle issue # Learn how to report an issue in Bundler
bundle licenses # Prints the license of all gems in the bundle
bundle lock # Creates a lockfile without installing
bundle open GEM # Opens the source directory of the given bundled gem
bundle outdated GEM [OPTIONS] # list installed gems with newer versions available
bundle package [OPTIONS] # Locks and then caches all of the gems into vendor/cache
bundle platform [OPTIONS] # Displays platform compatibility information
bundle plugin SUBCOMMAND ...ARGS # manage the bundler plugins
bundle pristine # Restores installed gems to pristine condition from files located in the gem cache. Gem installed from a git repository will be issued `git checkout --force`.
bundle show GEM [OPTIONS] # Shows all gems that are part of the bundle, or the path to a given gem
bundle update [OPTIONS] # update the current environment
bundle version # Prints the bundler's version information
bundle viz [OPTIONS] # Generates a visual dependency graph
Options:
[--no-color] # Disable colorization in output
-r, [--retry=NUM] # Specify the number of times you wish to attempt network commands
-V, [--verbose], [--no-verbose] # Enable verbose output mode
```
### Why did you choose this fix out of the possible options?
I chose this fix because it aligns the Bundler CLI with many other package managers that display a help message of some sort when invoked without arguments:
- CocoaPods
- npm
- RubyGems
- Homebrew
- pip
- Swift Package Manager
- Carthage
- Cargo
And unlike the following, which _do_ install by default:
- yarn
As to the particular format of the help printed, I thought something concise would be less disruptive than the full man page.
Improvements to the output would be welcome, this is just using the Thor default right now but we can easily implement our own. This will require test coverage, but I thought I'd hold off until the general change got some buy-in.
-rw-r--r-- | lib/bundler/cli.rb | 9 | ||||
-rw-r--r-- | lib/bundler/feature_flag.rb | 20 | ||||
-rw-r--r-- | spec/quality_spec.rb | 1 |
3 files changed, 25 insertions, 5 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index c09b14433a..94ca5dfa25 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -55,7 +55,14 @@ module Bundler check_unknown_options!(:except => [:config, :exec]) stop_on_unknown_option! :exec - default_task :install + desc "cli_help", "Prints a summary of bundler commands", :hide => true + def cli_help + version + Bundler.ui.info "\n" + self.class.help(shell) + end + default_task(Bundler.feature_flag.default_cli_command) + class_option "no-color", :type => :boolean, :desc => "Disable colorization in output" class_option "retry", :type => :numeric, :aliases => "-r", :banner => "NUM", :desc => "Specify the number of times you wish to attempt network commands" diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb index 0a3b010d1a..ee93773c2f 100644 --- a/lib/bundler/feature_flag.rb +++ b/lib/bundler/feature_flag.rb @@ -5,12 +5,24 @@ module Bundler unless Bundler::Settings::BOOL_KEYS.include?(flag.to_s) raise "Cannot use `#{flag}` as a settings feature flag since it isn't a bool key" end - define_method("#{flag}?") do - value = Bundler.settings[flag] + + settings_method("#{flag}?", flag, &default) + end + private_class_method :settings_flag + + def self.settings_option(key, &default) + settings_method(key, key, &default) + end + private_class_method :settings_option + + def self.settings_method(name, key, &default) + define_method(name) do + value = Bundler.settings[key] value = instance_eval(&default) if value.nil? && !default.nil? value end end + private_class_method :settings_method (1..10).each {|v| define_method("bundler_#{v}_mode?") { major_version >= v } } @@ -24,6 +36,8 @@ module Bundler settings_flag(:unlock_source_unlocks_spec) { !bundler_2_mode? } settings_flag(:update_requires_all_flag) { bundler_2_mode? } + settings_option(:default_cli_command) { bundler_2_mode? ? :cli_help : :install } + def initialize(bundler_version) @bundler_version = Gem::Version.create(bundler_version) end @@ -32,7 +46,5 @@ module Bundler @bundler_version.segments.first end private :major_version - - class << self; private :settings_flag; end end end diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb index c7b367ea87..44ec944eae 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -169,6 +169,7 @@ RSpec.describe "The library itself" do it "documents all used settings" do exemptions = %w[ + default_cli_command gem.coc gem.mit warned_version |