timr 0.3.0 → 0.4.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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.ackrc +9 -0
  3. data/.editorconfig +1 -0
  4. data/.env.example +7 -0
  5. data/.github/CONTRIBUTING.md +32 -0
  6. data/.github/ISSUE_TEMPLATE.md +13 -0
  7. data/.gitignore +8 -2
  8. data/.rdoc_options +21 -0
  9. data/.travis.yml +10 -7
  10. data/Gemfile +8 -0
  11. data/README.md +216 -3
  12. data/bin/.gitignore +2 -0
  13. data/bin/README.md +17 -0
  14. data/bin/build.sh +14 -0
  15. data/bin/build_api.sh +14 -0
  16. data/bin/build_coverage.sh +23 -0
  17. data/bin/build_info.sh +27 -0
  18. data/bin/build_man.sh +41 -0
  19. data/bin/clean.sh +14 -0
  20. data/bin/dev_setup.sh +19 -0
  21. data/bin/install.sh +49 -0
  22. data/bin/publish +38 -0
  23. data/bin/release.sh +35 -0
  24. data/bin/test.sh +19 -0
  25. data/bin/timr +20 -40
  26. data/bin/timr_bash_completion.sh +337 -0
  27. data/bin/uninstall.sh +24 -0
  28. data/lib/timr.rb +36 -8
  29. data/lib/timr/command/basic_command.rb +170 -0
  30. data/lib/timr/command/continue_command.rb +86 -0
  31. data/lib/timr/command/help_command.rb +137 -0
  32. data/lib/timr/command/log_command.rb +297 -0
  33. data/lib/timr/command/pause_command.rb +89 -0
  34. data/lib/timr/command/pop_command.rb +176 -0
  35. data/lib/timr/command/push_command.rb +141 -0
  36. data/lib/timr/command/report_command.rb +689 -0
  37. data/lib/timr/command/start_command.rb +172 -0
  38. data/lib/timr/command/status_command.rb +198 -0
  39. data/lib/timr/command/stop_command.rb +127 -0
  40. data/lib/timr/command/task_command.rb +318 -0
  41. data/lib/timr/command/track_command.rb +381 -0
  42. data/lib/timr/command/version_command.rb +18 -0
  43. data/lib/timr/duration.rb +159 -0
  44. data/lib/timr/exception/timr_error.rb +113 -0
  45. data/lib/timr/ext/time.rb +12 -0
  46. data/lib/timr/helper/datetime_helper.rb +128 -0
  47. data/lib/timr/helper/terminal_helper.rb +58 -0
  48. data/lib/timr/helper/translation_helper.rb +45 -0
  49. data/lib/timr/model/basic_model.rb +287 -0
  50. data/lib/timr/model/config.rb +48 -0
  51. data/lib/timr/model/foreign_id_db.rb +84 -0
  52. data/lib/timr/model/stack.rb +161 -0
  53. data/lib/timr/model/task.rb +1039 -0
  54. data/lib/timr/model/track.rb +589 -0
  55. data/lib/timr/progressbar.rb +41 -0
  56. data/lib/timr/simple_opt_parser.rb +230 -0
  57. data/lib/timr/status.rb +70 -0
  58. data/lib/timr/table.rb +88 -0
  59. data/lib/timr/timr.rb +500 -558
  60. data/lib/timr/version.rb +4 -15
  61. data/man/.gitignore +2 -0
  62. data/man/_footer +3 -0
  63. data/man/timr-continue.1 +48 -0
  64. data/man/timr-continue.1.ronn +39 -0
  65. data/man/timr-ftime.7 +77 -0
  66. data/man/timr-ftime.7.ronn +57 -0
  67. data/man/timr-log.1 +109 -0
  68. data/man/timr-log.1.ronn +87 -0
  69. data/man/timr-pause.1 +56 -0
  70. data/man/timr-pause.1.ronn +45 -0
  71. data/man/timr-pop.1 +66 -0
  72. data/man/timr-pop.1.ronn +53 -0
  73. data/man/timr-push.1 +25 -0
  74. data/man/timr-push.1.ronn +20 -0
  75. data/man/timr-report.1 +228 -0
  76. data/man/timr-report.1.ronn +193 -0
  77. data/man/timr-start.1 +100 -0
  78. data/man/timr-start.1.ronn +82 -0
  79. data/man/timr-status.1 +53 -0
  80. data/man/timr-status.1.ronn +42 -0
  81. data/man/timr-stop.1 +75 -0
  82. data/man/timr-stop.1.ronn +60 -0
  83. data/man/timr-task.1 +147 -0
  84. data/man/timr-task.1.ronn +115 -0
  85. data/man/timr-track.1 +109 -0
  86. data/man/timr-track.1.ronn +89 -0
  87. data/man/timr.1 +119 -0
  88. data/man/timr.1.ronn +68 -0
  89. data/timr.gemspec +18 -3
  90. data/timr.sublime-project +20 -1
  91. metadata +142 -23
  92. data/Makefile +0 -12
  93. data/Makefile.common +0 -56
  94. data/lib/timr/stack.rb +0 -81
  95. data/lib/timr/task.rb +0 -258
  96. data/lib/timr/track.rb +0 -167
  97. data/lib/timr/window.rb +0 -259
  98. data/lib/timr/window_help.rb +0 -41
  99. data/lib/timr/window_tasks.rb +0 -30
  100. data/lib/timr/window_test.rb +0 -20
  101. data/lib/timr/window_timeline.rb +0 -33
  102. data/tests/tc_stack.rb +0 -121
  103. data/tests/tc_task.rb +0 -190
  104. data/tests/tc_track.rb +0 -144
  105. data/tests/tc_window.rb +0 -428
  106. data/tests/ts_all.rb +0 -6
data/bin/uninstall.sh ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Uninstall gem.
4
+
5
+ SCRIPT_BASEDIR=$(dirname "$0")
6
+
7
+
8
+ set -e
9
+ which gem &> /dev/null || { echo 'ERROR: gem not found in PATH'; exit 1; }
10
+
11
+ cd "${SCRIPT_BASEDIR}/.."
12
+
13
+ # Load Environment Variables
14
+ [[ -f .env ]] && source .env
15
+
16
+ if [[ -z "${GEM_NAME}" ]] ; then
17
+ echo 'ERROR: one of the environment variables is missing'
18
+
19
+ echo "GEM_NAME: '${GEM_NAME}'"
20
+
21
+ exit 1
22
+ fi
23
+
24
+ gem uninstall "${GEM_NAME}" --all --executables
data/lib/timr.rb CHANGED
@@ -1,11 +1,39 @@
1
1
 
2
2
  require 'timr/version'
3
+ #require 'timr/simple_opt_parser'
4
+
5
+ require 'timr/ext/time'
6
+
7
+ require 'timr/exception/timr_error'
8
+
9
+ require 'timr/helper/datetime_helper'
10
+ require 'timr/helper/translation_helper'
11
+ require 'timr/helper/terminal_helper'
12
+
13
+ require 'timr/model/basic_model'
14
+ require 'timr/model/track'
15
+ require 'timr/model/task'
16
+ require 'timr/model/stack'
17
+ require 'timr/model/config'
18
+ require 'timr/model/foreign_id_db'
19
+ require 'timr/duration'
20
+ require 'timr/status'
21
+ require 'timr/table'
22
+ require 'timr/progressbar'
23
+
24
+ require 'timr/command/basic_command'
25
+ require 'timr/command/continue_command'
26
+ require 'timr/command/help_command'
27
+ require 'timr/command/log_command'
28
+ require 'timr/command/pause_command'
29
+ require 'timr/command/pop_command'
30
+ require 'timr/command/push_command'
31
+ require 'timr/command/report_command'
32
+ require 'timr/command/start_command'
33
+ require 'timr/command/status_command'
34
+ require 'timr/command/stop_command'
35
+ require 'timr/command/task_command'
36
+ require 'timr/command/track_command'
37
+ require 'timr/command/version_command'
38
+
3
39
  require 'timr/timr'
4
- require 'timr/stack'
5
- require 'timr/task'
6
- require 'timr/track'
7
- require 'timr/window'
8
- require 'timr/window_help'
9
- require 'timr/window_tasks'
10
- require 'timr/window_timeline'
11
- require 'timr/window_test'
@@ -0,0 +1,170 @@
1
+
2
+ require 'pathname'
3
+
4
+ module TheFox
5
+ module Timr
6
+ module Command
7
+
8
+ # Basic Class
9
+ class BasicCommand
10
+
11
+ include TheFox::Timr::Helper
12
+ include TheFox::Timr::Error
13
+
14
+ # Current Working Directory
15
+ attr_accessor :cwd
16
+
17
+ def initialize(argv = Array.new)
18
+ @cwd = nil
19
+ @timr = nil
20
+ end
21
+
22
+ # This is the actual execution of the Command.
23
+ def run
24
+ raise NotImplementedError
25
+ end
26
+
27
+ # Should be executed after `run` to gently save everything.
28
+ def shutdown
29
+ if @timr
30
+ @timr.shutdown
31
+ end
32
+ end
33
+
34
+ # All methods in this block are static.
35
+ class << self
36
+
37
+ include TheFox::Timr::Error
38
+
39
+ # Creates a new Command instance for each command string.
40
+ #
41
+ # For example, it returns a new StopCommand instance when `stop` String is provided by `argv` Array.
42
+ #
43
+ # Primary used by `bin/timr`.
44
+ def create_command_from_argv(argv)
45
+ # -C <path>
46
+ cwd_opt = Pathname.new("#{Dir.home}/.timr/defaultc").expand_path # Default Client
47
+
48
+ command_name = nil
49
+ command_argv = Array.new
50
+ loop_c = 0
51
+ while loop_c < 1024 && argv.length > 0
52
+ loop_c += 1
53
+ arg = argv.shift
54
+
55
+ if command_name
56
+ command_argv << arg
57
+ else
58
+ case arg
59
+ when '-h', '--help', 'help'
60
+ command_name = 'help'
61
+ when '-V', '--version'
62
+ command_name = 'version'
63
+ when '-C'
64
+ cwd_opt = Pathname.new(argv.shift).expand_path
65
+ when '--install-basepath'
66
+ timr_gem = Gem::Specification.find_by_name('timr')
67
+ print timr_gem.gem_dir
68
+ exit
69
+ else
70
+ if arg[0] == '-'
71
+ raise CommandError, "Unknown argument '#{arg}'. See 'timr --help'."
72
+ else
73
+ command_name = arg
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ command_class = get_command_class_by_name(command_name)
80
+ command = command_class.new(command_argv)
81
+ command.cwd = cwd_opt
82
+ command
83
+ end
84
+
85
+ # Get the Class for each command string.
86
+ def get_command_class_by_name(name)
87
+ case name
88
+ when 'help', '', nil
89
+ command = HelpCommand
90
+ when 'version'
91
+ command = VersionCommand
92
+
93
+ when 'status', 's'
94
+ command = StatusCommand
95
+ when 'start'
96
+ command = StartCommand
97
+ when 'stop'
98
+ command = StopCommand
99
+ when 'push'
100
+ command = PushCommand
101
+ when 'pop'
102
+ command = PopCommand
103
+ when 'continue', 'cont', 'c'
104
+ command = ContinueCommand
105
+ when 'pause', 'p'
106
+ command = PauseCommand
107
+ when 'log'
108
+ command = LogCommand
109
+ when 'task'
110
+ command = TaskCommand
111
+ when 'track'
112
+ command = TrackCommand
113
+ when 'report'
114
+ command = ReportCommand
115
+ else
116
+ raise CommandError, "'%s' is not a timr command. See 'timr --help'." % [name]
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ private
123
+
124
+ # Uses
125
+ # @timr
126
+ # @edit_opt
127
+ # @task_id_opt
128
+ # @track_id_opt
129
+ def run_edit(task_id = nil, track_id = nil)
130
+ task_id ||= @task_id_opt
131
+ track_id ||= @track_id_opt
132
+
133
+ if @timr && @edit_opt
134
+ edit_text = Array.new
135
+
136
+ if @message_opt
137
+ edit_text << @message_opt.clone
138
+ else
139
+ track = @timr.get_track_by_task_id(task_id, track_id)
140
+
141
+ if track && track.message
142
+ edit_text << track.message.clone
143
+ else
144
+ edit_text << @message_opt.clone
145
+ end
146
+ end
147
+
148
+ TerminalHelper.external_editor_help(edit_text)
149
+
150
+ editor_message = TerminalHelper.run_external_editor(edit_text)
151
+
152
+ if editor_message.length > 0
153
+ @message_opt = editor_message
154
+ end
155
+ end
156
+ end
157
+
158
+ def check_foreign_id(foreign_id)
159
+ if foreign_id && foreign_id.match(/ /)
160
+ foreign_id_without_spaces = foreign_id.gsub(' ', '')
161
+
162
+ raise ForeignIdError, "Foreign ID (--id) cannot include spaces. Maybe you want to use '#{foreign_id_without_spaces}' instead."
163
+ end
164
+ end
165
+
166
+ end # class Command
167
+
168
+ end # module Command
169
+ end # module Timr
170
+ end # module TheFox
@@ -0,0 +1,86 @@
1
+
2
+ module TheFox
3
+ module Timr
4
+ module Command
5
+
6
+ # Continue the previous paused [Track](rdoc-ref:TheFox::Timr::Model::Track).
7
+ #
8
+ # Man page: [timr-continue(1)](../../../../man/timr-continue.1.html)
9
+ class ContinueCommand < BasicCommand
10
+
11
+ include TheFox::Timr::Helper
12
+ include TheFox::Timr::Error
13
+
14
+ # Path to man page.
15
+ MAN_PATH = 'man/timr-continue.1'
16
+
17
+ def initialize(argv = Array.new)
18
+ super()
19
+
20
+ @help_opt = false
21
+
22
+ @date_opt = nil
23
+ @time_opt = nil
24
+
25
+ loop_c = 0 # Limit the loop.
26
+ while loop_c < 1024 && argv.length > 0
27
+ loop_c += 1
28
+ arg = argv.shift
29
+
30
+ case arg
31
+ when '-h', '--help'
32
+ @help_opt = true
33
+ when '-d', '--date'
34
+ @date_opt = argv.shift
35
+ when '-t', '--time'
36
+ @time_opt = argv.shift
37
+ else
38
+ raise ContinueCommandError, "Unknown argument '#{arg}'. See 'timr continue --help'."
39
+ end
40
+ end
41
+ end
42
+
43
+ # See BasicCommand#run.
44
+ def run
45
+ if @help_opt
46
+ help
47
+ return
48
+ end
49
+
50
+ @timr = Timr.new(@cwd)
51
+
52
+ options = {
53
+ :date => @date_opt,
54
+ :time => @time_opt,
55
+ }
56
+
57
+ track = @timr.continue(options)
58
+ unless track
59
+ puts 'No running Track to continue.'
60
+ return
61
+ end
62
+
63
+ puts '--- CONTINUED ---'
64
+ puts track.to_compact_str
65
+ puts @timr.stack
66
+ end
67
+
68
+ private
69
+
70
+ def help
71
+ puts 'usage: timr continue [-d|--date <date>] [-t|--time <time>]'
72
+ puts ' or: timr continue [-h|--help]'
73
+ puts
74
+ puts 'Track Options'
75
+ puts ' -d, --date <date> Track Start Date'
76
+ puts ' -t, --time <time> Track Start Time'
77
+ puts
78
+ HelpCommand.print_datetime_help
79
+ puts
80
+ end
81
+
82
+ end # class ContinueCommand
83
+
84
+ end # module Command
85
+ end # module Timr
86
+ end # module TheFox
@@ -0,0 +1,137 @@
1
+
2
+ module TheFox
3
+ module Timr
4
+ module Command
5
+
6
+ # Print the overview help page.
7
+ class HelpCommand < BasicCommand
8
+
9
+ def initialize(argv = Array.new)
10
+ # puts "help #{argv}"
11
+
12
+ super()
13
+
14
+ @command_opt = nil
15
+
16
+ loop_c = 0 # Limit the loop.
17
+ while loop_c < 1024 && argv.length > 0
18
+ loop_c += 1
19
+
20
+ unless @command_opt
21
+ @command_opt = argv.shift
22
+ end
23
+ end
24
+ end
25
+
26
+ # See BasicCommand#run.
27
+ def run
28
+ if @command_opt
29
+ command_class = BasicCommand.get_command_class_by_name(@command_opt)
30
+
31
+ if defined?(command_class::MAN_PATH)
32
+ system("man #{command_class::MAN_PATH}")
33
+ else
34
+ raise HelpCommandError, "No manual page found for '#{@command_opt}'. See 'timr --help'."
35
+ end
36
+ else
37
+ help
38
+ end
39
+ end
40
+
41
+ # All methods in this block are static.
42
+ class << self
43
+
44
+ # Alias
45
+ def print_id_help
46
+ print_task_id_help
47
+ puts
48
+ print_track_id_help
49
+ end
50
+
51
+ # Print help about Task ID.
52
+ def print_task_id_help
53
+ puts ' <task_id> Task ID (SHA1 hex)'
54
+ puts ' If not specified a new Task will be created.'
55
+ end
56
+
57
+ # Print help about Track ID.
58
+ def print_track_id_help
59
+ puts ' <track_id> Track ID (SHA1 hex)'
60
+ puts ' If specified a new Track with the same'
61
+ puts ' message will be created.'
62
+ end
63
+
64
+ # Print DateTime help.
65
+ def print_datetime_help
66
+ puts 'DateTime Formats'
67
+ puts " <date_time> A DateTime is one single string"
68
+ puts " representing '<date> <time>'."
69
+ puts ' <date> Formats: YYYYMMDD, YYYY-MM-DD, MM/DD/YYYY, DD.MM.YYYY'
70
+ puts ' <time> Formats: HH:MM, HH:MM:SS'
71
+ end
72
+
73
+ # Print Estimation help.
74
+ def print_estimation_help(ext = false)
75
+ puts 'Duration'
76
+ puts ' Duration is parsed by chronic_duration.'
77
+ puts ' Examples:'
78
+ puts " -e 2:10:5 # Sets Estimation to 2h 10m 5s."
79
+ puts " -e '2h 10m 5s' # Sets Estimation to 2h 10m 5s."
80
+ puts
81
+ if ext
82
+ puts " Use '+' or '-' to calculate with Estimation Times:"
83
+ puts " -e '-45m' # Subtracts 45 minutes from the original Estimation."
84
+ puts " -e '+1h 30m' # Adds 1 hour 30 minutes to the original Estimation."
85
+ puts
86
+ end
87
+ puts ' See chronic_duration for more examples.'
88
+ puts ' https://github.com/henrypoydar/chronic_duration'
89
+ end
90
+
91
+ # Print Man Units help.
92
+ def print_man_units_help
93
+ puts 'Man Units'
94
+ puts ' 8 hours are 1 man-day.'
95
+ puts ' 5 man-days are 1 man-week, and so on.'
96
+ end
97
+
98
+ end
99
+
100
+ private
101
+
102
+ def help
103
+ puts 'usage: timr [-V|--version] [-h|--help] [-C <path>] <command> [<args>]'
104
+ puts
105
+ puts ' -V, --version Show version.'
106
+ puts ' -h, --help Show help.'
107
+ puts ' -C <path> Set path to the project base directory.'
108
+ puts ' Default: ~/.timr/defaultc'
109
+ puts
110
+ puts 'Commands'
111
+ puts ' start Start working on a Task.'
112
+ puts ' stop Stop the current running Task/Track.'
113
+ puts
114
+ puts ' pause Pause the Top Track of the Stack.'
115
+ puts ' continue Continue the Top Track of the Stack.'
116
+ puts
117
+ puts ' push Push a new Track on the Stack and pause the old one.'
118
+ puts ' pop Pop the Top Track and continue the old one.'
119
+ puts
120
+ puts ' status Show the current Stack.'
121
+ puts ' log Show recent Tracks.'
122
+ puts
123
+ puts " task Task related commands. See 'timr task --help'."
124
+ puts " track Track related commands. See 'timr track --help'."
125
+ puts
126
+ puts ' report Generate a report.'
127
+ puts
128
+ puts "See 'timr <command> --help' to read details about a specific command,"
129
+ puts " or 'timr help <command>' to open the man page for this command."
130
+ puts "Also see 'man' directory for available man pages."
131
+ end
132
+
133
+ end # class HelpCommand
134
+
135
+ end # module Command
136
+ end # module Timr
137
+ end # module TheFox