Class: KBSecret::CLI::Command::Todo

Inherits:
Abstract
  • Object
show all
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

#cli

Instance Method Summary collapse

Methods inherited from Abstract

command_name, config

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.banner = <<~HELP
        Usage:
          kbsecret todo <start|suspend|complete> <record>
      HELP

      o.string "-s", "--session", "the session to search in", default: :default
    end

    cli.dreck do
      string :command
      string :label
    end

    cli.ensure_session!
  end
end

Instance Method Details

#complete_todovoid

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

See Also:



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

See Also:



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_todovoid

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_todovoid

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

See Also:



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