Class: TermDump::Command
- Inherits:
-
Object
- Object
- TermDump::Command
- Defined in:
- lib/termdump/command.rb
Instance Method Summary collapse
-
#initialize(args) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/termdump/command.rb', line 9 def initialize args @args = OpenStruct.new(:stdout => false, :action => :load, :list => false, :session => '', :exclude => false) OptionParser.new do |opts| opts. = "Usage: termdump [options] [session]" opts.on('-i', '--init', 'initialize configure interactively') { @args.action = :init } opts.on('-e', '--edit [session]', 'edit session') do |name| @args.action = :edit name.nil? ? @args.list = true : @args.session = name end opts.on('-d', '--delete [session]', 'delete session') do |name| @args.action = :delete name.nil? ? @args.list = true : @args.session = name end opts.on('-s', '--save [session]', 'save session') do |name| @args.action = :save name.nil? ? @args.list = true : @args.session = name end opts.on_tail('--stdout', 'print dump result to stdout while saving a session') { @args.stdout = true } opts.on_tail('--exclude', 'exclude current pty while saving a session') { @args.exclude = true } opts.on_tail('-l', '--list', 'list all sessions') { @args.list = true } opts.on_tail('-v', '--version', 'print version') do puts VERSION exit 0 end begin opts.parse! args rescue OptionParser::InvalidOption puts opts.help exit 1 end # :load is the default action if no option given if @args.action == :load args.size > 0 ? @args.session = args[0] : @args.list = true end # --stdout should be used with --save if @args.stdout || @args.exclude if @args.action != :save puts opts.help exit 1 end end end end |
Instance Method Details
#run ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/termdump/command.rb', line 64 def run main = Main.new if @args.action == :save main.save @args.session, @args.stdout, @args.exclude elsif @args.action == :init main.init elsif @args.list main.list @args.action else name = @args.session case @args.action when :delete main.delete_session name when :edit main.edit_session name when :load main.load_session name end end end |