Class: DevSystem::SimpleCommand

Inherits:
BaseCommand show all
Defined in:
lib/dev_system/sub/command/commands/simple_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#env

Instance Method Summary collapse

Methods inherited from BaseCommand

call, get_command_signatures

Methods inherited from Command

call, get_command_signatures

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Instance Method Details

#call(env) ⇒ Object



5
6
7
8
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 5

def call(env)
  env[:simple] = [""]
  super
end

#log_simple_rememberObject



12
13
14
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 12

def log_simple_remember
  log :lower, "env[:remember] is now #{stick system.color, (env[:simple].join " ")}", kaller: caller
end

#simple_arg(index, &block) ⇒ Object

arg0 arg1 arg2



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 72

def simple_arg(index, &block)
  string = env[:args][index]
  return string if string

  value = yield
  value = "" if value.nil?
  value = value.inspect if value.include? " "
  log :high, value.inspect

  string = env[:simple][0]
  string << " " unless string.empty?
  string << value

  log_simple_remember

  value
end

#simple_arg_ask(index, title) ⇒ Object

arg0 arg1 arg2



93
94
95
96
97
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 93

def simple_arg_ask(index, title)
  simple_arg index do
    TtyInputCommand.prompt.ask(title)
  end
end

#simple_arg_ask_snakecase(index, title) ⇒ Object

arg0 arg1 arg2



102
103
104
105
106
107
108
109
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 102

def simple_arg_ask_snakecase(index, title)
  simple_arg index do
    TtyInputCommand.prompt.ask(title) do |q|
      q.required true
      q.validate /^[a-zA-Z_]*$/
    end.snakecase
  end
end

#simple_argsObject

arg0 arg1 arg2



64
65
66
67
68
69
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 64

def simple_args
  env[:args]
    .reject { _1.start_with? "+" }
    .reject { _1.start_with? "-" }
    .reject { _1.include? "=" }
end

#simple_boolean(key, &block) ⇒ Object

+key -key



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 128

def simple_boolean(key, &block)
  return true  if env[:args].find { _1 == "+#{key}" }
  return false if env[:args].find { _1 == "-#{key}" }

  value = yield
  log :high, value.inspect

  env[:simple] << "+#{key}" if TrueClass === value
  env[:simple] << "-#{key}" if FalseClass === value

  log_simple_remember

  value
end

#simple_boolean_no(key, title) ⇒ Object

+key -key



121
122
123
124
125
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 121

def simple_boolean_no(key, title)
  simple_boolean key do
    TtyInputCommand.prompt.no? title
  end
end

#simple_boolean_yes(key, title) ⇒ Object

+key -key



114
115
116
117
118
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 114

def simple_boolean_yes(key, title)
  simple_boolean key do
    TtyInputCommand.prompt.yes? title
  end
end

#simple_color(key, string: "I LOVE RUBY") ⇒ Object

key=value



36
37
38
39
40
41
42
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 36

def simple_color(key, string: "I LOVE RUBY")
  simple_string key do
    TtyInputCommand.pick_color string: string
  end.to_sym.tap do |color|
    log :high, color.inspect
  end
end

#simple_controller_placement(key, places) ⇒ Object

key=value



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 47

def simple_controller_placement(key, places)
  simple_string key do
    options = places.map do |place, path|
      [
        "#{place.ljust 30} path: #{path}",
        place
      ]
    end.to_h
    TtyInputCommand.pick_one "Where should the controller be placed?", options
  end.tap do |place|
    log :high, place.inspect
  end
end

#simple_string(key, &block) ⇒ Object

key=value



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dev_system/sub/command/commands/simple_command.rb', line 19

def simple_string(key, &block)
  string = env[:args].find { _1.start_with? "#{key}=" }.to_s.sub("#{key}=", "")
  return string unless string.empty?

  value = yield.to_s.split(" ")[0]
  log :high, value.inspect

  env[:simple] << "#{key}=#{value}"

  log_simple_remember

  value
end