wlog 1.0.0 → 1.0.5

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/README.md +57 -9
  4. data/Rakefile +24 -0
  5. data/bin/wlog +10 -0
  6. data/lib/wlog/commands/archive_finished_issues.rb +20 -0
  7. data/lib/wlog/commands/archive_issues.rb +22 -0
  8. data/lib/wlog/commands/concat_description.rb +8 -2
  9. data/lib/wlog/commands/delete_issue.rb +31 -0
  10. data/lib/wlog/commands/innit_db.rb +0 -2
  11. data/lib/wlog/commands/make_csv.rb +7 -1
  12. data/lib/wlog/commands/new_entry.rb +7 -2
  13. data/lib/wlog/commands/replace_pattern.rb +4 -6
  14. data/lib/wlog/commands/taint_setup.rb +18 -0
  15. data/lib/wlog/db_registry.rb +3 -5
  16. data/lib/wlog/domain.rb +13 -0
  17. data/lib/wlog/domain/attachment.rb +25 -17
  18. data/lib/wlog/domain/helpers.rb +4 -0
  19. data/lib/wlog/domain/issue.rb +77 -23
  20. data/lib/wlog/domain/key_value.rb +21 -17
  21. data/lib/wlog/domain/log_entry.rb +35 -21
  22. data/lib/wlog/domain/session.rb +17 -0
  23. data/lib/wlog/domain/sql_modules/issue_sql.rb +13 -5
  24. data/lib/wlog/domain/static_configurations.rb +9 -0
  25. data/lib/wlog/domain/sys_config.rb +76 -6
  26. data/lib/wlog/domain/template_engine.rb +55 -0
  27. data/lib/wlog/domain/timelog_helper.rb +53 -0
  28. data/lib/wlog/sql/seq/2.sql +4 -0
  29. data/lib/wlog/{domain → tech}/ansi_colors.rb +7 -6
  30. data/lib/wlog/tech/uncolored_string.rb +14 -0
  31. data/lib/wlog/tech/wlog_string.rb +23 -0
  32. data/lib/wlog/ui/bootstrap.rb +18 -0
  33. data/lib/wlog/ui/cli_interface.rb +94 -34
  34. data/lib/wlog/ui/commands/create_issue.rb +8 -4
  35. data/lib/wlog/ui/issue_ui.rb +47 -41
  36. data/lib/wlog/ui/setup_wizard.rb +34 -0
  37. data/lib/wlog/version.rb +1 -1
  38. data/spec/domain/attachment_spec.rb +59 -0
  39. data/spec/domain/commands/concat_desc_spec.rb +51 -0
  40. data/spec/domain/commands/new_entry_spec.rb +41 -0
  41. data/spec/domain/commands/replace_pattern_spec.rb +46 -0
  42. data/spec/domain/issue_spec.rb +127 -0
  43. data/spec/domain/key_value_spec.rb +42 -0
  44. data/spec/domain/log_entry_spec.rb +85 -0
  45. data/spec/domain/sys_config_spec.rb +38 -0
  46. data/spec/make_db.rb +8 -0
  47. data/spec/old-databases/README.md +6 -0
  48. data/spec/old-databases/default +0 -0
  49. data/spec/tech/uncolored_string.rb +20 -0
  50. data/spec/tech/wlog_string_spec.rb +46 -0
  51. data/wlog.gemspec +5 -3
  52. metadata +44 -6
  53. data/spec/key_vale_spec.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f836fd871076bafbd84142635212cf9e375ab42
4
- data.tar.gz: bafc3472bdff32399995f256d52b3ad7fe47ebe2
3
+ metadata.gz: f4675d5ea8306d4dc0cc233a7a10a33ba4eb75b5
4
+ data.tar.gz: 84bb925bc393f021267b20ea3e9c0c944daf87fc
5
5
  SHA512:
6
- metadata.gz: 0fe3b1b4222f094092869ece6b7b82b54a6e83ae1be3b1f74b560f70e0e7c08a0885d4de802b7dbe718c29659340a893ee38931e217ab56d986ef39859cd1802
7
- data.tar.gz: e991c87b690f1e472c871c681bc66f0edc2122359dbe5cc9d4648fda6097e848c2f3d7069a2f6ee0f7892514dae0a7a078c1ad070bf624bc76d9fe023dd81403
6
+ metadata.gz: 3fdf0f23d629a0e4a599daa732113d8e90a39653f2ebece0343301115f8cdc3deacc2f8d6a1a663d5ea5f8aae8e51e45dc99be340ecdd67711a322b5a81fddb9
7
+ data.tar.gz: 9376a739b679b3f1931f8dbba6a6d9a73018c03f9601c3c1874ba9dcb961ed11d069369d479528742c1e077bb4a6a46b288e5f154ac872b1f886fb2e3189b7b1
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # wlog ![Code Climate](https://codeclimate.com/github/psyomn/wlog.png)
1
+ # wlog [![Code Climate](https://codeclimate.com/github/psyomn/wlog.png)](https://codeclimate.com/github/psyomn/wlog)
2
2
 
3
3
  wlog (worklog) is a small utility to track tasks in command line. I use this
4
4
  for things I work on and need to submit a list of stuff done on a particular
@@ -75,12 +75,12 @@ potential of this application.
75
75
 
76
76
  You can list the available databases by running the following command:
77
77
 
78
- wlog --list
78
+ wlog --list
79
79
 
80
80
  If for some reason you need to check out where the application stores the
81
81
  databases, you can do the following:
82
82
 
83
- wlog --where
83
+ wlog --where
84
84
 
85
85
  That will print the absolute path to that directory.
86
86
 
@@ -95,9 +95,11 @@ So when you start the application this is what you see:
95
95
  Enter the command `show` to list the issues
96
96
 
97
97
  [wlog] show
98
- 1 [started work] - This issue is here to ...
99
- 2 [finished] - This issue is here to treat you better than the last one
100
- 3 [new] - this issue just does not belong
98
+ started work 2
99
+ [6] Fix colors for wlog and make it pretty
100
+ [4] Weird bug crash when pressing ctrl+d
101
+ new 1
102
+ [3] Need to check out templating system
101
103
 
102
104
  Now we want to focus on a particular issue. We type in `focus`
103
105
 
@@ -109,11 +111,51 @@ Now we want to focus on a particular issue. We type in `focus`
109
111
  And now we can show all the logged work with `show`:
110
112
 
111
113
  [issue #1] show
112
- 2013-10-13 - Sunday [2]
113
- [4] I did some work on this issue [15:34:08]
114
- [5] Some trivial work there too [15:35:32]
114
+ 2013-10-13 - Sunday [2]
115
+ [4] I did some work on this issue [15:34:08]
116
+ [5] Some trivial work there too [15:35:32]
115
117
  [issue #1]
116
118
 
119
+ To exit the scope of an issue, you can use the `forget` command:
120
+
121
+ [issue #1] forget
122
+ [wlog]
123
+
124
+ If you forgot what you are doing, you can do
125
+
126
+ [issue #1] desc
127
+ + Issue #6
128
+ - Reported : 2013-10-26 15:01:45 -0400
129
+ - Due : 1969-12-31 19:00:00 -0500
130
+ - Entries : 0
131
+ - Status : started work
132
+ - Time : 3h
133
+
134
+ - Whatever description you wrote for issue 1
135
+
136
+ You can also attach files to issues
137
+
138
+ [wlog] attach
139
+ Attach to which issue? : 1
140
+ Absolute file location : /tmp/derp.txt
141
+ Alias name for file (optional) :
142
+ Attached file.
143
+
144
+ And then you can output them to a location:
145
+
146
+ [wlog] show
147
+ finished [1]
148
+ [2] This is yet another issue
149
+ started work [1]
150
+ [1] This is my issue
151
+ [wlog] showattach
152
+ Which issue : 1
153
+ [1] - derp.txt (alias: )
154
+ [2] - derp.txt (alias: )
155
+ [wlog] outattach
156
+ Which attachment to output? : 1
157
+ Output where (abs dir) : /tmp/
158
+
117
159
  You can run these commands in this 'sub-shell':
118
160
  are `show`, `search`, `replace`, `delete`, and `concat`.
119
161
 
@@ -134,3 +176,9 @@ are `show`, `search`, `replace`, `delete`, and `concat`.
134
176
  3. Commit your changes (`git commit -am 'Add some feature'`)
135
177
  4. Push to the branch (`git push origin my-new-feature`)
136
178
  5. Create new Pull Request
179
+
180
+ ### For newcommers
181
+
182
+ Look at the github issues, for things marked as 'Up for Grabs'. Feel free to
183
+ message me to ask anything. I'll be more than happy to answer.
184
+
data/Rakefile CHANGED
@@ -10,8 +10,19 @@ YARD::Rake::YardocTask.new do |t|
10
10
  t.options = ['--title', 'Wlog: the friendly worktime logger!', '-o', 'doc/']
11
11
  end
12
12
 
13
+ # Anything that has to do with the stuff of this gem in .config/wlog
14
+ namespace :data do
15
+ desc "Remove all configuration data of wlog"
16
+ task :rm do
17
+ include Wlog::StaticConfigurations
18
+ print "You sure you want to remove #{AppDirectory}? [y/n] :"
19
+ FileUtils.rm_rf AppDirectory if $stdin.gets.match(/^y/i)
20
+ end
21
+ end
22
+
13
23
  namespace :db do
14
24
  # Remove data directory. This will remove all your data
25
+ desc "Remove All the databases"
15
26
  task :rm do
16
27
  include Wlog::StaticConfigurations
17
28
  puts "Removing data directories from #{DataDirectory}"
@@ -26,6 +37,19 @@ namespace :db do
26
37
  end
27
38
  end
28
39
 
40
+ namespace :reek do
41
+ desc "Run reek at lib/"
42
+ task :all do
43
+ sh "reek lib/"
44
+ end
45
+
46
+ desc "Grep long parameter list"
47
+ task :lparam do
48
+ sh "reek 2>&1 lib/ | grep -i param"
49
+ end
50
+
51
+ end
52
+
29
53
  namespace :test do
30
54
  task :all => :spec
31
55
  end
data/bin/wlog CHANGED
@@ -2,22 +2,32 @@
2
2
 
3
3
  require 'wlog/version'
4
4
  require 'wlog/domain/static_configurations'
5
+ require 'wlog/ui/bootstrap'
5
6
  require 'wlog/ui/cli_interface'
6
7
 
7
8
  include Wlog
9
+
8
10
 
9
11
  if ARGV.size > 0
10
12
  case ARGV[0]
11
13
  when "--list"
14
+ # TODO FIXME
12
15
  CliInterface.list_databases
13
16
  when '--where'
14
17
  puts StaticConfigurations::DataDirectory
18
+ when '--version', '-v'
19
+ print "wlog "
20
+ puts Wlog::VERSION
15
21
  when /--/
16
22
  puts "Unknown command."
17
23
  else
24
+ # Make overall configurations
25
+ Bootstrap.configure!
18
26
  CliInterface.new.run
19
27
  end
20
28
  else
29
+ # Make overall configurations
30
+ Bootstrap.configure!
21
31
  CliInterface.new.run
22
32
  end
23
33
 
@@ -0,0 +1,20 @@
1
+ require 'wlog/commands/commandable'
2
+ require 'wlog/commands/archive_issues'
3
+ require 'wlog/domain/issue'
4
+
5
+ module Wlog
6
+ # MacroCommand that archives finished issues
7
+ # @author Simon Symeonidis
8
+ class ArchiveFinishedIssues < Commandable
9
+
10
+ def initialize(db)
11
+ @issues = Issue.find_all_finished(db)
12
+ @arch_command = ArchiveIssues.new(@issues)
13
+ end
14
+
15
+ def execute
16
+ @arch_command.execute
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'wlog/commands/commandable'
2
+ require 'wlog/domain/issue'
3
+
4
+ module Wlog
5
+ # Command. Given a list of issues, mark them as archived.
6
+ # @author Simon Symeonidis
7
+ class ArchiveIssues < Commandable
8
+
9
+ def initialize(issues)
10
+ @issues = issues
11
+ end
12
+
13
+ # Update the issues to be marked as archived
14
+ def execute
15
+ @issues.each do |issue|
16
+ issue.archive!
17
+ issue.update
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -4,18 +4,24 @@ require 'wlog/domain/log_entry'
4
4
  module Wlog
5
5
  # Concatenate a string to an existing log entry
6
6
  class ConcatDescription < Commandable
7
- def initialize(id, str)
7
+ def initialize(db, id, str)
8
8
  @id = id; @str = str
9
+ @db = db
9
10
  end
10
11
 
11
12
  # Find and update the log entry
12
13
  def execute
13
- log_entry = LogEntry.find(@id)
14
+ log_entry = LogEntry.find(@db, @id)
14
15
  log_entry.description.concat(str)
15
16
  log_entry.update
16
17
  end
17
18
 
18
19
  attr_reader :id, :str
20
+
21
+ private
22
+
23
+ attr :db
24
+
19
25
  end
20
26
  end # end Wlog module
21
27
 
@@ -0,0 +1,31 @@
1
+ require 'wlog/commands/commandable'
2
+ require 'wlog/domain/issue'
3
+
4
+ module Wlog
5
+ # Command for deleting issues
6
+ # @author Simon Symeonidis
7
+ class DeleteIssue
8
+ # Init with the db handle, and issue id
9
+ def initialize(db, id)
10
+ @db = db
11
+ @issue_id = id
12
+ @deleted = false
13
+ end
14
+
15
+ # delete the issue
16
+ def execute
17
+ issue = Issue.find(@db, @issue_id)
18
+ if issue
19
+ issue.delete
20
+ @deleted = true
21
+ end
22
+ end
23
+
24
+ def deleted?
25
+ @deleted
26
+ end
27
+
28
+ attr :deleted
29
+ end
30
+ end
31
+
@@ -3,7 +3,6 @@ require 'turntables/turntable'
3
3
  require 'wlog/db_registry'
4
4
  require 'wlog/commands/commandable'
5
5
  require 'wlog/domain/static_configurations'
6
- require 'wlog/domain/helpers'
7
6
 
8
7
  module Wlog
9
8
  # Command to create the initial database
@@ -11,7 +10,6 @@ module Wlog
11
10
  class InnitDb < Commandable
12
11
  include StaticConfigurations
13
12
  def execute
14
- Helpers.make_dirs!
15
13
  current_dir = "#{File.expand_path File.dirname(__FILE__)}/../sql"
16
14
  turntable = Turntables::Turntable.new
17
15
  turntable.register(current_dir)
@@ -6,9 +6,15 @@ module Wlog
6
6
  # Create a Csv report with this command
7
7
  # @author Simon Symeonidis
8
8
  class MakeCsv < Commandable
9
+
10
+ def initialize(db)
11
+ @db = db
12
+ end
13
+
14
+ # TODO refactor me. Because I feel like a horrible piece of code.
9
15
  def execute
10
16
  str = ""
11
- LogEntry.find_all.group_by{|el| el.date.strftime("%Y-%m-%d")}.each_pair do |key,value|
17
+ LogEntry.find_all(@db).group_by{|el| el.date.strftime("%Y-%m-%d")}.each_pair do |key,value|
12
18
  str.concat("#{value.first.date.strftime("%A")} #{key}\n")
13
19
  value.each do |entry|
14
20
  str.concat(",\"#{Helpers.break_string(entry.description,80)}\"#{$/}")
@@ -2,12 +2,17 @@ require 'wlog/commands/commandable'
2
2
  require 'wlog/domain/log_entry'
3
3
 
4
4
  module Wlog
5
+ # Command to create a log entry given an issue id, and a string
6
+ # @author Simon Symeonidis
5
7
  class NewEntry < Commandable
6
8
 
7
- def initialize(desc,issue_id); @desc, @iid = desc, issue_id end
9
+ def initialize(db, desc, issue_id)
10
+ @desc, @iid = desc, issue_id
11
+ @db = db
12
+ end
8
13
 
9
14
  def execute
10
- log_entry = LogEntry.new
15
+ log_entry = LogEntry.new(@db)
11
16
  log_entry.description = @desc
12
17
  log_entry.issue_id = @iid
13
18
  log_entry.insert
@@ -5,17 +5,15 @@ module Wlog
5
5
  # Command that replaces a string pattern found in an entry, with another string
6
6
  # @author Simon Symeonidis
7
7
  class ReplacePattern < Commandable
8
- def initialize(id, oldpat, newpat)
9
- @id, @oldpat, @newpat = id, oldpat, newpat
8
+ def initialize(db, id, oldpat, newpat)
9
+ @db, @id, @oldpat, @newpat = db, id, oldpat, newpat
10
10
  end
11
11
 
12
12
  def execute
13
- log_entry = LogEntry.find(id)
14
- log_entry.description.gsub!(old_pattern, new_pattern)
13
+ log_entry = LogEntry.find(@db, @id)
14
+ log_entry.description.gsub!(@oldpat, @newpat)
15
15
  log_entry.update
16
16
  end
17
-
18
- attr_reader :id, :oldpat, :newpat
19
17
  end
20
18
  end
21
19
 
@@ -0,0 +1,18 @@
1
+ require 'fileutils'
2
+ require 'wlog/commands/commandable'
3
+ require 'wlog/domain/static_configurations'
4
+
5
+ module Wlog
6
+ # This touches a file in wlog config: .config/wlog/tainted. That file is used
7
+ # later on to see if this is the first setup or not.
8
+ class TaintSetup
9
+ include StaticConfigurations
10
+ def initialize
11
+ end
12
+
13
+ def execute
14
+ FileUtils.touch TaintFile
15
+ end
16
+ end
17
+ end
18
+
@@ -1,18 +1,16 @@
1
- require 'singleton'
2
1
  require 'sqlite3'
3
2
  require 'fileutils'
4
3
 
5
4
  require 'wlog/domain/static_configurations.rb'
6
5
 
7
6
  module Wlog
7
+ # The db registry, using sqlite3
8
8
  # @author Simon Symeonidis
9
- # The db registry, using sqlite3
10
9
  class DbRegistry
11
- include Singleton
12
10
  include StaticConfigurations
13
11
 
14
- def initialize
15
- @handle = SQLite3::Database.new("#{DataDirectory}#{ARGV[0] || DefaultDb}")
12
+ def initialize(dbname)
13
+ @handle = SQLite3::Database.new(dbname || "#{DataDirectory}#{ARGV[0] || DefaultDb}")
16
14
  end
17
15
 
18
16
  # execute a sql with varargs parameters
@@ -0,0 +1,13 @@
1
+ # Quickhand to include the rest of the domain objects
2
+
3
+ require 'wlog/domain/attachment.rb'
4
+ require 'wlog/domain/helpers.rb'
5
+ require 'wlog/domain/issue.rb'
6
+ require 'wlog/domain/key_value.rb'
7
+ require 'wlog/domain/log_entry.rb'
8
+ require 'wlog/domain/session.rb'
9
+ require 'wlog/domain/static_configurations.rb'
10
+ require 'wlog/domain/sys_config.rb'
11
+ require 'wlog/domain/template_engine.rb'
12
+ require 'wlog/domain/timelog_helper.rb'
13
+
@@ -11,46 +11,51 @@ class Attachment
11
11
 
12
12
  # Can only initialize with a caller name and id, since relations to
13
13
  # attachments are polymorphic.
14
- def initialize(caller_name, caller_id)
15
- @caller_name, @caller_id = caller_name, caller_id
14
+ def initialize(dbhandle, caller_name, caller_id)
15
+ @caller_name, @caller_id, @db = caller_name, caller_id, dbhandle
16
16
  end
17
17
 
18
18
  # Find an attachment given an id
19
19
  # @param id is the attachment id to find
20
- def self.find_all_by_discriminator(name, id)
20
+ def self.find_all_by_discriminator(db, name, id)
21
21
  arr = Array.new
22
- rows = DbRegistry.instance.execute(
22
+ rows = db.execute(
23
23
  PolymorphicAttachmentsSql::SelectSql, name, id)
24
24
 
25
25
  rows.each do |row|
26
- arr.push self.find(name, row[2])
26
+ arr.push self.find(db, name, row[2])
27
27
  end
28
28
  arr end
29
29
 
30
30
  # Delete an attachment
31
31
  # @param id the attachment with the id to delete
32
- def self.delete_by_discriminator(name, id)
33
- DbRegistry.instance.execute(DeleteSql, id)
32
+ def delete_by_discriminator(name, id)
33
+ @db.execute(DeleteSql, id)
34
34
  end
35
35
 
36
36
  # Find an attachment by an identifier and polymorphic name
37
37
  # @param id is the identifier of the attachment to find
38
38
  # @param name is the name of the polymorphic thing
39
- def self.find(name, id)
40
- row = DbRegistry.instance.execute(AttachmentSql::SelectSql, id).first
41
- att = Attachment.new(name, id)
42
- att.quick_assign!(row)
39
+ def self.find(db, name, id)
40
+ row = db.execute(AttachmentSql::SelectSql, id).first
41
+ att = nil
42
+ if row && !row.empty?
43
+ att = Attachment.new(db, name, id)
44
+ att.quick_assign!(row)
45
+ end
43
46
  att end
44
47
 
45
48
  # Insert an attachment. This also creates the relation in the polymorphic
46
49
  # table.
47
50
  def insert
48
- DbRegistry.instance.execute(
49
- AttachmentSql::InsertSql, @filename, @given_name, @data)
50
- ret = DbRegistry.instance.last_row_from(AttachmentSql::TableName)
51
- @id = ret.first[0].to_i
52
- DbRegistry.instance.execute(
53
- PolymorphicAttachmentsSql::InsertSql, @caller_name, @caller_id, @id)
51
+ unless @id
52
+ @db.execute(
53
+ AttachmentSql::InsertSql, @filename, @given_name, @data)
54
+ ret = @db.last_row_from(AttachmentSql::TableName)
55
+ @id = ret.first[0].to_i
56
+ @db.execute(
57
+ PolymorphicAttachmentsSql::InsertSql, @caller_name, @caller_id, @id)
58
+ end
54
59
  end
55
60
 
56
61
  # Assign a row of data to self
@@ -75,6 +80,9 @@ class Attachment
75
80
 
76
81
  # The caller id of the calling object
77
82
  attr_accessor :caller_id
83
+
84
+ # The database handle for the active record
85
+ attr_accessor :db
78
86
  end
79
87
  end # module Wlog
80
88