dsu 0.1.0.alpha.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -39
- data/lib/dsu/base_cli.rb +0 -3
- data/lib/dsu/cli.rb +42 -49
- data/lib/dsu/command_services/add_entry_service.rb +21 -21
- data/lib/dsu/models/entry.rb +37 -20
- data/lib/dsu/models/entry_group.rb +66 -38
- data/lib/dsu/services/configuration_loader_service.rb +4 -3
- data/lib/dsu/services/entry_group_editor_service.rb +99 -0
- data/lib/dsu/services/entry_group_writer_service.rb +1 -0
- data/lib/dsu/services/stdout_redirector_service.rb +27 -0
- data/lib/dsu/services/temp_file_reader_service.rb +8 -8
- data/lib/dsu/services/temp_file_writer_service.rb +6 -6
- data/lib/dsu/subcommands/edit.rb +8 -79
- data/lib/dsu/support/colorable.rb +1 -0
- data/lib/dsu/support/descriptable.rb +43 -0
- data/lib/dsu/support/entry_group_loadable.rb +10 -12
- data/lib/dsu/validators/description_validator.rb +38 -0
- data/lib/dsu/validators/entries_validator.rb +43 -31
- data/lib/dsu/validators/time_validator.rb +11 -20
- data/lib/dsu/version.rb +1 -1
- data/lib/dsu/views/edited_entries/shared/errors.rb +39 -0
- data/lib/dsu/views/entry_group/edit.rb +30 -33
- data/lib/dsu/views/entry_group/show.rb +12 -10
- data/lib/dsu/views/shared/messages.rb +56 -0
- data/lib/dsu.rb +4 -0
- metadata +10 -8
- data/lib/dsu/support/commander/command.rb +0 -130
- data/lib/dsu/support/commander/command_help.rb +0 -62
- data/lib/dsu/support/commander/subcommand.rb +0 -45
- data/lib/dsu/support/interactive/cli.rb +0 -161
@@ -1,161 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../ask'
|
4
|
-
require_relative '../colorable'
|
5
|
-
require_relative '../say'
|
6
|
-
|
7
|
-
module Dsu
|
8
|
-
module Interactive
|
9
|
-
class Cli
|
10
|
-
include Support::Colorable
|
11
|
-
include Support::Ask
|
12
|
-
include Support::Say
|
13
|
-
|
14
|
-
BACK_COMMANDS = %w[b].freeze
|
15
|
-
EXIT_COMMANDS = %w[x].freeze
|
16
|
-
HELP_COMMANDS = %w[?].freeze
|
17
|
-
PROMPT_TOKEN = '>'
|
18
|
-
|
19
|
-
attr_reader :name, :parent, :prompt
|
20
|
-
|
21
|
-
def initialize(name:, parent: nil, **options)
|
22
|
-
@name = name
|
23
|
-
@parent = parent
|
24
|
-
@prompt = options[:prompt]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Starts our interactive loop.
|
28
|
-
def start
|
29
|
-
help
|
30
|
-
process_commands
|
31
|
-
end
|
32
|
-
|
33
|
-
def process(command:)
|
34
|
-
if command.cancelled?
|
35
|
-
nil
|
36
|
-
elsif help?(command.command)
|
37
|
-
help
|
38
|
-
elsif back_or_exit?(command.command)
|
39
|
-
parent&.help
|
40
|
-
else
|
41
|
-
unrecognized_command command.command
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Dispays the full help; header and body.
|
46
|
-
def help
|
47
|
-
help_header
|
48
|
-
help_body
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# This is our interaction loop. Commands that are NOT help or
|
54
|
-
# back or exit commands are yielded to the subclass to execute. Help
|
55
|
-
# commands simply display help; back (or exit) commands transfer control
|
56
|
-
# back to the parent cli (if parent? is true) or exits the current
|
57
|
-
# cli (if parent? is false) respectfully.
|
58
|
-
def process_commands
|
59
|
-
loop do
|
60
|
-
command = wrap_command(ask)
|
61
|
-
process(command: command)
|
62
|
-
next if command.cancelled?
|
63
|
-
break if back_or_exit?(command.command)
|
64
|
-
end
|
65
|
-
say 'Done.', ABORTED unless parent?
|
66
|
-
end
|
67
|
-
|
68
|
-
def wrap_command(command)
|
69
|
-
Struct.new(:command, :args, :cancelled, keyword_init: true) do
|
70
|
-
def cancelled?
|
71
|
-
cancelled
|
72
|
-
end
|
73
|
-
|
74
|
-
def cancelled!
|
75
|
-
self[:cancelled] = true
|
76
|
-
end
|
77
|
-
end.new(
|
78
|
-
command: command.split[0],
|
79
|
-
args: command.split[1..],
|
80
|
-
cancelled: false
|
81
|
-
)
|
82
|
-
end
|
83
|
-
|
84
|
-
# This is the full prompt that needs to be displayed that includes
|
85
|
-
# all parent prompts, right down to the current prompt.
|
86
|
-
def full_prompt
|
87
|
-
prompts = full_prompt_build prompts: []
|
88
|
-
prompt_token = "#{PROMPT_TOKEN} "
|
89
|
-
"#{prompts.join prompt_token}#{prompt_token}"
|
90
|
-
end
|
91
|
-
|
92
|
-
def parent?
|
93
|
-
!parent.nil?
|
94
|
-
end
|
95
|
-
|
96
|
-
def back?(command)
|
97
|
-
back_commands.include? command
|
98
|
-
end
|
99
|
-
|
100
|
-
def back_commands
|
101
|
-
@back_commands ||= BACK_COMMANDS
|
102
|
-
end
|
103
|
-
|
104
|
-
def exit?(command)
|
105
|
-
exit_commands.include? command
|
106
|
-
end
|
107
|
-
|
108
|
-
def exit_commands
|
109
|
-
@exit_commands ||= EXIT_COMMANDS
|
110
|
-
end
|
111
|
-
|
112
|
-
def back_or_exit?(command)
|
113
|
-
(back_commands + exit_commands).include? command
|
114
|
-
end
|
115
|
-
|
116
|
-
def help?(command)
|
117
|
-
help_commands.include? command
|
118
|
-
end
|
119
|
-
|
120
|
-
# Returns what are considered to be commands associated with
|
121
|
-
# displaying help.
|
122
|
-
def help_commands
|
123
|
-
@help_commands ||= HELP_COMMANDS
|
124
|
-
end
|
125
|
-
|
126
|
-
# Displays the help header; override this if you want to customize
|
127
|
-
# your own help header in your subclass.
|
128
|
-
def help_header
|
129
|
-
say "#{name} Help", HIGHLIGHT
|
130
|
-
say '---', HIGHLIGHT
|
131
|
-
end
|
132
|
-
|
133
|
-
# Override this in your subclass and call super AFTER you've
|
134
|
-
# displayed your subclass' help body.
|
135
|
-
def help_body
|
136
|
-
say "[#{HELP_COMMANDS.join(' | ')}] Display help", HIGHLIGHT
|
137
|
-
say "[#{BACK_COMMANDS.join(' | ')}] Go back", HIGHLIGHT if parent?
|
138
|
-
say "[#{EXIT_COMMANDS.join(' | ')}] Exit", HIGHLIGHT unless parent?
|
139
|
-
end
|
140
|
-
|
141
|
-
# This simply outputs our prompt and accepts user input.
|
142
|
-
def ask
|
143
|
-
super full_prompt
|
144
|
-
end
|
145
|
-
|
146
|
-
def unrecognized_command(command)
|
147
|
-
say "Unrecognized command (\"#{command}\"). Try again.", ERROR
|
148
|
-
end
|
149
|
-
|
150
|
-
# Builds the full prompt to be used which amounts to:
|
151
|
-
# <parent cli prompt> PROMPT_TOKEN <child cli 1 prompt>
|
152
|
-
# PROMPT_TOKEN <child 2 cli prompt> ...
|
153
|
-
def full_prompt_build(prompts:)
|
154
|
-
parent.send(:full_prompt_build, prompts: prompts) if parent?
|
155
|
-
|
156
|
-
prompts << prompt
|
157
|
-
prompts.flatten
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|