Module: Git::Gsub
- Defined in:
- lib/git/gsub.rb,
lib/git/gsub/version.rb
Defined Under Namespace
Modules: Commands
Constant Summary collapse
- VERSION =
'0.0.10'.freeze
Class Method Summary collapse
Class Method Details
.run(argv) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/git/gsub.rb', line 10 def self.run(argv) opts = OptionParser.new self.class.module_eval do define_method(:usage) do |msg = nil| puts opts.to_s puts "error: #{msg}" if msg exit 1 end end = {} opts.on('-v', '--version', 'Print version') do |_v| [:version] = true end opts.on('--snake', 'Experimental: substitute snake-cased expressions') do |_v| [:snake] = true end opts.on('--camel', 'Experimental: substitute camel-cased expressions') do |_v| [:camel] = true end opts.on('--kebab', 'Experimental: substitute kebab-cased expressions') do |_v| [:kebab] = true end opts.on('--rename', 'Rename files along with substitution') do |_v| [:rename] = true end opts.on('--dry-run', 'Print commands to be run') do |_v| [:dry] = true end opts. = 'Usage: git gsub [options] FROM TO [PATHS]' begin args = opts.parse(argv) rescue OptionParser::InvalidOption => e usage e. end if [:version] version else from, to, *paths = args usage 'No FROM given' unless from usage 'No TO given' unless to Commands::Gsub.new(from, to, paths, ).run Commands::Rename.new(from, to, paths, ).run if [:rename] end end |