Class: GitBlur::CmdParser
- Inherits:
-
Object
- Object
- GitBlur::CmdParser
- Defined in:
- lib/git-blur/cmdparser.rb
Instance Attribute Summary collapse
-
#cmds ⇒ Object
Returns the value of attribute cmds.
Instance Method Summary collapse
- #cmd_clean ⇒ Object
- #cmd_diff ⇒ Object
- #cmd_help ⇒ Object
- #cmd_init ⇒ Object
- #cmd_smudge ⇒ Object
- #cmd_version ⇒ Object
- #desc_clean ⇒ Object
- #desc_diff ⇒ Object
- #desc_help ⇒ Object
- #desc_init ⇒ Object
- #desc_smudge ⇒ Object
- #desc_version ⇒ Object
-
#initialize ⇒ CmdParser
constructor
A new instance of CmdParser.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CmdParser
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
#cmds ⇒ Object
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_clean ⇒ Object
47 48 49 |
# File 'lib/git-blur/cmdparser.rb', line 47 def cmd_clean GitBlur::Actions.new.clean end |
#cmd_diff ⇒ Object
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_help ⇒ Object
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_init ⇒ Object
42 43 44 |
# File 'lib/git-blur/cmdparser.rb', line 42 def cmd_init GitBlur::Actions.new( true ).init end |
#cmd_smudge ⇒ Object
52 53 54 |
# File 'lib/git-blur/cmdparser.rb', line 52 def cmd_smudge GitBlur::Actions.new.smudge end |
#cmd_version ⇒ Object
57 58 59 |
# File 'lib/git-blur/cmdparser.rb', line 57 def cmd_version puts "git-blur #{GitBlur::VERSION}" end |
#desc_clean ⇒ Object
46 |
# File 'lib/git-blur/cmdparser.rb', line 46 def desc_clean() "Encrypt stdin into stdout" end |
#desc_diff ⇒ Object
69 |
# File 'lib/git-blur/cmdparser.rb', line 69 def desc_diff() "Decrypt a file into stdout" end |
#desc_help ⇒ Object
61 |
# File 'lib/git-blur/cmdparser.rb', line 61 def desc_help() "Show help" end |
#desc_init ⇒ Object
41 |
# File 'lib/git-blur/cmdparser.rb', line 41 def desc_init() "Initialize crypo keys and git configuration" end |
#desc_smudge ⇒ Object
51 |
# File 'lib/git-blur/cmdparser.rb', line 51 def desc_smudge() "Decrypt stdin into stdout" end |
#desc_version ⇒ Object
56 |
# File 'lib/git-blur/cmdparser.rb', line 56 def desc_version() "Show git-blur version" end |
#run ⇒ Object
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 |