Class: GitBlur::CmdParser

Inherits:
Object
  • Object
show all
Defined in:
lib/git-blur/cmdparser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCmdParser

Returns a new instance of CmdParser.



10
11
12
13
14
15
16
# File 'lib/git-blur/cmdparser.rb', line 10

def initialize
  @cmds = Hash[ self.methods.select do |mn|
    mn.to_s.index( "cmd_" ) == 0
  end.map do |mn|
    [ mn.slice( 4, mn.length ) , self.method( mn ) ] 
  end ]
end

Instance Attribute Details

#cmdsObject

Returns the value of attribute cmds.



8
9
10
# File 'lib/git-blur/cmdparser.rb', line 8

def cmds
  @cmds
end

Instance Method Details

#cmd_cleanObject



47
48
49
# File 'lib/git-blur/cmdparser.rb', line 47

def cmd_clean
  GitBlur::Actions.new.clean
end

#cmd_diffObject



70
71
72
73
74
75
# File 'lib/git-blur/cmdparser.rb', line 70

def cmd_diff
  if ARGV.length < 2
    raise "Missing file"
  end
  GitBlur::Actions.new.diff ARGV[1]
end

#cmd_helpObject



62
63
64
65
66
67
# File 'lib/git-blur/cmdparser.rb', line 62

def cmd_help
  puts "git-blur transparently encrypts and decrypts files in your repo"
  puts "Usage: git blur command [opts]"
  puts ""
  puts command_list
end

#cmd_initObject



42
43
44
# File 'lib/git-blur/cmdparser.rb', line 42

def cmd_init
  GitBlur::Actions.new( true ).init
end

#cmd_smudgeObject



52
53
54
# File 'lib/git-blur/cmdparser.rb', line 52

def cmd_smudge
  GitBlur::Actions.new.smudge
end

#cmd_versionObject



57
58
59
# File 'lib/git-blur/cmdparser.rb', line 57

def cmd_version
  puts "git-blur #{GitBlur::VERSION}"
end

#desc_cleanObject



46
# File 'lib/git-blur/cmdparser.rb', line 46

def desc_clean() "Encrypt stdin into stdout" end

#desc_diffObject



69
# File 'lib/git-blur/cmdparser.rb', line 69

def desc_diff() "Decrypt a file into stdout" end

#desc_helpObject



61
# File 'lib/git-blur/cmdparser.rb', line 61

def desc_help() "Show help" end

#desc_initObject



41
# File 'lib/git-blur/cmdparser.rb', line 41

def desc_init() "Initialize crypo keys and git configuration" end

#desc_smudgeObject



51
# File 'lib/git-blur/cmdparser.rb', line 51

def desc_smudge() "Decrypt stdin into stdout" end

#desc_versionObject



56
# File 'lib/git-blur/cmdparser.rb', line 56

def desc_version() "Show git-blur version" end

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/git-blur/cmdparser.rb', line 19

def run
  cmd = ARGV[0]

  if cmd == "--help"
    cmd_help
    return
  end

  if not @cmds.include? cmd
    msg = String.new
    if cmd.nil?
      msg += "Missing command\n"
    else
      msg += "Unknown command #{cmd}\n"
    end
    msg += "\n" + command_list
    raise msg
  end

  @cmds[ cmd ].call
end