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

  options = {}
  opts.on('-v', '--version', 'Print version') do |_v|
    options[:version] = true
  end

  opts.on('--snake', 'Experimental: substitute snake-cased expressions') do |_v|
    options[:snake] = true
  end

  opts.on('--camel', 'Experimental: substitute camel-cased expressions') do |_v|
    options[:camel] = true
  end

  opts.on('--kebab', 'Experimental: substitute kebab-cased expressions') do |_v|
    options[:kebab] = true
  end

  opts.on('--rename', 'Rename files along with substitution') do |_v|
    options[:rename] = true
  end

  opts.on('--dry-run', 'Print commands to be run') do |_v|
    options[:dry] = true
  end

  opts.banner = 'Usage: git gsub [options] FROM TO [PATHS]'

  begin
    args = opts.parse(argv)
  rescue OptionParser::InvalidOption => e
    usage e.message
  end

  if options[: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, options).run
    Commands::Rename.new(from, to, paths, options).run if options[:rename]
  end
end

.versionObject



65
66
67
# File 'lib/git/gsub.rb', line 65

def self.version
  puts Git::Gsub::VERSION
end