dsu 0.1.0.alpha.5 → 1.1.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile.lock +6 -15
  5. data/README.md +33 -47
  6. data/lib/dsu/base_cli.rb +13 -6
  7. data/lib/dsu/cli.rb +46 -55
  8. data/lib/dsu/command_services/add_entry_service.rb +21 -21
  9. data/lib/dsu/core/ruby/not_today.rb +11 -0
  10. data/lib/dsu/models/entry.rb +32 -21
  11. data/lib/dsu/models/entry_group.rb +41 -105
  12. data/lib/dsu/services/configuration_loader_service.rb +19 -2
  13. data/lib/dsu/services/entry_group_editor_service.rb +37 -89
  14. data/lib/dsu/services/stdout_redirector_service.rb +27 -0
  15. data/lib/dsu/subcommands/list.rb +83 -15
  16. data/lib/dsu/support/colorable.rb +1 -0
  17. data/lib/dsu/support/command_options/dsu_times.rb +33 -0
  18. data/lib/dsu/support/command_options/time.rb +77 -0
  19. data/lib/dsu/support/command_options/time_mneumonic.rb +127 -0
  20. data/lib/dsu/support/command_options/time_mneumonics.rb +15 -0
  21. data/lib/dsu/support/configurable.rb +15 -0
  22. data/lib/dsu/support/configuration.rb +13 -1
  23. data/lib/dsu/support/entry_group_fileable.rb +31 -6
  24. data/lib/dsu/support/entry_group_loadable.rb +13 -16
  25. data/lib/dsu/support/entry_group_viewable.rb +26 -8
  26. data/lib/dsu/support/times_sortable.rb +1 -3
  27. data/lib/dsu/validators/description_validator.rb +38 -0
  28. data/lib/dsu/validators/entries_validator.rb +43 -32
  29. data/lib/dsu/validators/time_validator.rb +11 -20
  30. data/lib/dsu/version.rb +1 -1
  31. data/lib/dsu/views/edited_entries/shared/errors.rb +39 -0
  32. data/lib/dsu/views/entry_group/edit.rb +89 -39
  33. data/lib/dsu/views/entry_group/show.rb +10 -4
  34. data/lib/dsu/views/shared/messages.rb +56 -0
  35. data/lib/dsu.rb +8 -2
  36. metadata +24 -12
  37. data/lib/dsu/support/commander/command.rb +0 -130
  38. data/lib/dsu/support/commander/command_help.rb +0 -62
  39. data/lib/dsu/support/commander/subcommand.rb +0 -45
  40. 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