Class: KBSecret::CLI::Command::Todo
- Defined in:
- lib/kbsecret/cli/command/todo.rb
Overview
The implementation of kbsecret todo
.
Constant Summary collapse
- SUBCOMMANDS =
The list of subcommands supported by
kbsecret todo
. %w[start suspend complete].freeze
Instance Attribute Summary
Attributes inherited from Abstract
Instance Method Summary collapse
-
#complete_todo ⇒ void
private
Completes the todo associated with the current invocation, unless already completed.
-
#initialize(argv) ⇒ Todo
constructor
A new instance of Todo.
- #run! ⇒ Object
- #setup! ⇒ Object
-
#start_todo ⇒ void
private
Starts the todo associated with the current invocation, unless already started.
-
#suspend_todo ⇒ void
private
Suspends the todo associated with the current invocation, unless already suspended.
- #validate! ⇒ Object
Methods inherited from Abstract
Constructor Details
#initialize(argv) ⇒ Todo
Returns a new instance of Todo.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kbsecret/cli/command/todo.rb', line 11 def initialize(argv) super(argv) do |cli| cli.slop cmds: SUBCOMMANDS do |o| o. = " Usage:\n kbsecret todo <start|suspend|complete> <record>\n HELP\n\n o.string \"-s\", \"--session\", \"the session to search in\", default: :default\n end\n\n cli.dreck do\n string :command\n string :label\n end\n\n cli.ensure_session!\n end\nend\n" |
Instance Method Details
#complete_todo ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Completes the todo associated with the current invocation, unless already completed.
73 74 75 76 77 |
# File 'lib/kbsecret/cli/command/todo.rb', line 73 def complete_todo cli.die "That task is already completed!" if @todo.completed? @todo.complete! puts "#{@todo.label}: '#{@todo.todo}' marked as completed at #{@todo.stop}" end |
#run! ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/kbsecret/cli/command/todo.rb', line 44 def run! case @subcmd when "start" then start_todo when "suspend" then suspend_todo when "complete" then complete_todo end end |
#setup! ⇒ Object
32 33 34 35 |
# File 'lib/kbsecret/cli/command/todo.rb', line 32 def setup! @todo = cli.session[cli.args[:label]] @subcmd = cli.args[:command] end |
#start_todo ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Starts the todo associated with the current invocation, unless already started.
55 56 57 58 59 |
# File 'lib/kbsecret/cli/command/todo.rb', line 55 def start_todo cli.die "That task is already started!" if @todo.started? @todo.start! puts "#{@todo.label}: '#{@todo.todo}' marked as started at #{@todo.start}" end |
#suspend_todo ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Suspends the todo associated with the current invocation, unless already suspended.
64 65 66 67 68 |
# File 'lib/kbsecret/cli/command/todo.rb', line 64 def suspend_todo cli.die "That task is already suspended!" if @todo.suspended? @todo.suspend! puts "#{@todo.label}: '#{@todo.todo}' marked as suspended at #{@todo.stop}" end |
#validate! ⇒ Object
38 39 40 41 |
# File 'lib/kbsecret/cli/command/todo.rb', line 38 def validate! cli.die "No such todo record: #{@todo}." unless @todo && @todo.type == :todo cli.die "Unknown subcommand: #{@subcmd}." unless SUBCOMMANDS.include?(@subcmd) end |