Class: Breezer::Command
- Inherits:
-
Object
- Object
- Breezer::Command
- Defined in:
- lib/breezer/command.rb
Overview
Used to parse the command line args and run the breezer accordingly
Class Method Summary collapse
-
.check_files_presence!(gemfile_file, lockfile_file) ⇒ Object
Check that the Gemfile and the Lockfile exists.
- .get_gemfile_file(args) ⇒ Object
-
.parse_options(options = { debug: false }, argv) ⇒ Object
rubocop:todo Metrics/AbcSize.
- .run!(args) ⇒ Object
Class Method Details
.check_files_presence!(gemfile_file, lockfile_file) ⇒ Object
Check that the Gemfile and the Lockfile exists
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/breezer/command.rb', line 25 def check_files_presence!(gemfile_file, lockfile_file) unless File.file?(gemfile_file) puts "Unable to find a Gemfile (searched in #{gemfile_file})" raise NoGemfileException, "Unable to find a Gemfile (searched in #{gemfile_file})" end return if File.file?(lockfile_file) puts "Unable to find a Lockfile (Gemfile.lock). If you don't have a Gemfile.lock yet, "\ "you can run 'bundle install' first. (searched in #{lockfile_file})" raise NoLockfileException, "Unable to find a Lockfile (Gemfile.lock) (searched in #{lockfile_file})" end |
.get_gemfile_file(args) ⇒ Object
39 40 41 42 43 |
# File 'lib/breezer/command.rb', line 39 def get_gemfile_file(args) gemfile_dir = args.first || '.' File.directory?(gemfile_dir) ? File.join(gemfile_dir, 'Gemfile') : gemfile_dir end |
.parse_options(options = { debug: false }, argv) ⇒ Object
rubocop:todo Metrics/AbcSize
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/breezer/command.rb', line 45 def ( = { debug: false }, argv) # rubocop:todo Metrics/AbcSize OptionParser.new do |parser| # rubocop:todo Metrics/BlockLength parser. = 'Usage: breezer DIR [options]' parser.on('-l', '--level LEVEL', 'Set the minimum level of gem updates (default: patch).'\ ' Set to "exact" to lock gems versions (not recommended).') do |v| unless %w[major minor patch exact].include?(v) raise InvalidLevelException, "Error: level must be one of: 'major', 'minor', 'patch' or 'exact', #{v} given." end [:level] = v end parser.on('-L', '--lockfile NAME', 'Use different lockfile (default: Gemfile.lock)') do |v| [:lockfile_file] = v end parser.on('-d', '--dry-run', 'Print the updated Gemfile instead of writing it') do [:dry] = true end parser.on('-o', '--output FILE', 'The output file (default: Gemfile)') do |v| [:output] = v end parser.on('-c', '--check', 'Check that all gems have version constraints') do |_v| [:check] = true end parser.on('-h', '--help', 'Show this help message') do puts parser exit(0) end parser.on('-v', '--version', 'Show version') do puts Breezer::VERSION exit(0) end end.parse!(argv) end |
.run!(args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/breezer/command.rb', line 12 def run!(args) gemfile_file = get_gemfile_file(args) = ({ debug: false }, args) lockfile_file = [:lockfile_file] || "#{gemfile_file}.lock" # Will raise if files are not valid check_files_presence!(gemfile_file, lockfile_file) Breezer.freeze!(gemfile_file, lockfile_file, ) end |