Class: Rgc::ArgParser

Inherits:
Object
  • Object
show all
Includes:
GLI::App
Defined in:
lib/rgc/arg_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv, argf) ⇒ ArgParser

Returns a new instance of ArgParser.



5
6
7
8
9
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
# File 'lib/rgc/arg_parser.rb', line 5

def initialize(argv, argf)
  program_desc 'Program to encrypt certain files inside git repository.'

  version Rgc::VERSION

  pre do |global,command,options,args|
    # Pre logic here
    # Return true to proceed; false to abort and not call the
    # chosen command
    # Use skips_pre before a command to skip this block
    # on that command only
    true
  end

  post do |global,command,options,args|
    # Post logic here
    # Use skips_post before a command to skip this
    # block on that command only
  end

  on_error do |exception|
    # Error logic here
    # return false to skip default error handling
    puts exception.backtrace
    true
  end

  init_keygen
  init_init
  init_encrypt
  init_clean
  init_smudge

  exit run(ARGV)
end

Instance Method Details

#init_cleanObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/rgc/arg_parser.rb', line 63

def init_clean
  desc('encrypt content of STDIN and write to STDOUT')

  command(:clean) do |c|

    c.action do |global_options, options, args|
      Rgc::Clean.new(global_options, options, args)
    end
  end
end

#init_encryptObject



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rgc/arg_parser.rb', line 85

def init_encrypt
  desc('set files for encryption')

  command(:encrypt) do |c|

    c.flag [:yaml, :y], desc: "yaml values to encrypt"

    c.action do |global_options, options, args|
      Rgc::Encrypt.new(global_options, options, args)
    end
  end
end

#init_initObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/rgc/arg_parser.rb', line 52

def init_init
  desc('prepare git repository to use rgc with given key file')

  command(:init) do |c|

    c.action do |global_options, options, args|
      Rgc::Init.new(global_options, options, args)
    end
  end
end

#init_keygenObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/rgc/arg_parser.rb', line 41

def init_keygen
  desc('generate a rgc key in the given file')

  command(:keygen) do |c|

    c.action do |global_options, options, args|
      Rgc::Keygen.new(global_options, options, args)
    end
  end
end

#init_smudgeObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/rgc/arg_parser.rb', line 74

def init_smudge
  desc('decrypt content of STDIN and write to STDOUT')

  command(:smudge) do |c|

    c.action do |global_options, options, args|
      Rgc::Smudge.new(global_options, options, args)
    end
  end
end