gwtf 0.4.0 → 0.4.1

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.
@@ -8,6 +8,8 @@ module Gwtf
8
8
  require 'fileutils'
9
9
  require 'tempfile'
10
10
  require 'uri'
11
+ require 'time'
12
+ require 'readline'
11
13
 
12
14
  def self.each_command
13
15
  commands_dir = File.join(File.dirname(__FILE__), "gwtf", "commands")
@@ -43,6 +45,17 @@ module Gwtf
43
45
  end
44
46
  end
45
47
 
48
+ def self.ask(prompt="")
49
+ stty_save = `stty -g`.chomp
50
+
51
+ begin
52
+ return Readline.readline("#{prompt} ", true)
53
+ rescue Interrupt => e
54
+ system('stty', stty_save)
55
+ raise
56
+ end
57
+ end
58
+
46
59
  # borrowed from ohai, thanks Adam.
47
60
  def self.seconds_to_human(seconds)
48
61
  days = seconds.to_i / 86400
@@ -10,25 +10,31 @@ command [:edit, :vi, :e] do |c|
10
10
  if args.size == 1
11
11
  raise "EDITOR environment variable should be set" unless ENV.include?("EDITOR")
12
12
 
13
- descr_sep = "== EDIT BETWEEN THESE LINES =="
14
-
15
- temp_item = {"description" => "#{descr_sep}\n#{item.description}\n#{descr_sep}", "subject" => item.subject}
16
-
17
13
  begin
18
14
  tmp = Tempfile.new("gwtf")
19
- tmp.write(temp_item.to_yaml)
15
+ tmp.puts "Subject: %s" % [ item.subject ]
16
+ tmp.puts "Description:"
17
+ tmp.puts item.description if item.description
20
18
  tmp.rewind
21
19
  system("%s %s" % [ENV["EDITOR"], tmp.path])
22
- edited_item = YAML.load_file(tmp.path)
20
+ edited_item = File.read(tmp.path)
23
21
  ensure
24
22
  tmp.close
25
23
  tmp.unlink
26
24
  end
27
25
 
28
- item.subject = edited_item["subject"] if edited_item["subject"]
26
+ if edited_item.split("\n").first =~ /^Subject:\s*(.+)/
27
+ item.subject = $1
28
+ else
29
+ raise "Subject is required"
30
+ end
31
+
32
+ description = edited_item.split("\n")[2..-1]
29
33
 
30
- if edited_item["description"] =~ /#{descr_sep}\n(.+)\n#{descr_sep}/m
31
- item.description = $1
34
+ unless [description].flatten.compact.empty?
35
+ item.description = description.join("\n")
36
+ else
37
+ item.description = nil
32
38
  end
33
39
 
34
40
  item.save
@@ -23,8 +23,7 @@ command [:list, :ls, :l] do |c|
23
23
  items = Gwtf::Items.new(File.join(global_options[:data], project), project)
24
24
  stats = items.stats
25
25
 
26
- puts "%#{longest_name + 3}s: open: %3d: closed %3d: total: %3d" % [ project, stats["open"], stats["closed"], stats["total"] ] unless stats["total"] == 0
27
-
26
+ puts "%#{longest_name + 3}s: open: %3d: closed %3d: total: %3d" % [ project, stats["open"], stats["closed"], stats["total"] ] unless stats["open"] == 0
28
27
  end
29
28
 
30
29
  puts
@@ -20,10 +20,10 @@ command :shell do |c|
20
20
 
21
21
  STDOUT.sync = true
22
22
 
23
- print "Optional description for work log (start with done! to close): "
24
23
 
25
24
  begin
26
- description = STDIN.gets.chomp
25
+ description = Gwtf.ask "Optional description for work log (start with done! to close): "
26
+
27
27
  if description =~ /^(done|close)!\s*(.+)/
28
28
  description = $2
29
29
  item.close
@@ -1,3 +1,3 @@
1
1
  module Gwtf
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gwtf
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - R.I.Pienaar
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-15 00:00:00 +00:00
18
+ date: 2012-03-18 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency