beastie 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a7c105f90e9690b9a2c2aeff5d6f9ce642b079
4
- data.tar.gz: d64ed0a580dae6f716c7cb8e7d26ad1131225fec
3
+ metadata.gz: ccbf340538f8102a4cd65ad060dc3d3f55280936
4
+ data.tar.gz: 5c9c471a6e322b44cc91052c1b10cdfe4b245b60
5
5
  SHA512:
6
- metadata.gz: 869f0cc4e4adaf5b085da54e7d6d23ea7ccd0d238811d179ee9ad629bf213d8caa416fae27096c71717f6690385d3a83ec117557b06cff9cf93b8e69bb96adf8
7
- data.tar.gz: 85c0eb98dc47bf34060374d25ae2c26ecc9a61cc56f4cfb7d2881778f300cf665fcaf558da681770dfe74240c34320ee36d7c3b45c931570affe8e254810ccf2
6
+ metadata.gz: 22d310d93c27c2b332f8f3d9ecc9b68578cacf66b3fd0d2f713f4b5bc2a3d907130946045b15321f562f68307f6e74563739d5bcc3d8bea33bad6c4fc7b10baa
7
+ data.tar.gz: 8cb5a966918a470a61ba21da439d7a75701f2fed29fd74543cf7afdd051aed1d8fd4ccc308e3ccf7ca091c9d015d3e3fa32a7ef7a6c25d7303317c9b8a8545f4
data/README.textile CHANGED
@@ -30,6 +30,8 @@ Main commands:
30
30
 
31
31
  - @beastie new@ := asks information about an issue and generate a YAML file in the current directory.
32
32
 
33
+ - @beastie nedit@ := enter a new issue using the default editor (@nedit@ = new and edit; see @edit@ for the specificaiton of the editor)
34
+
33
35
  - @beastie list@ := reads all YAML files in the current directory and generate a list of all the issues.
34
36
 
35
37
  - @beastie show N@ := shows issue @N@, where @N@ is the identifier shown by the @beastie list@ command.
data/lib/beastie/issue.rb CHANGED
@@ -23,37 +23,48 @@ module Beastie
23
23
  #
24
24
  # - for each field, the structure if the following:
25
25
  #
26
- # field name => init value, prompt
26
+ # field name => input function, default value, prompt
27
27
  #
28
28
  # where
29
- # * "init value" is evaluated (use "gets.chomp" to ask input)
30
- # * prompt is what is asked to the user. Use an empty string for
31
- # a value which is filled automatically.
32
- #
29
+ #
30
+ # * "input function" is a function to ask a value to the user. Use an empty
31
+ # string for a value which is filled automatically
32
+ #
33
+ # * "default value" is the default value to assign to the field
34
+ #
35
+ # * "prompt" is what is asked to the user. Use an empty string for
36
+ # a value which is filled automatically.
37
+ #
38
+ # input function and default value are evaluated, so that computation can be performed
39
+ #
33
40
  # - title, created, and status are compulsory: do not delete them
34
41
  # (gen_filename depends upon title and created; the close
35
42
  # command depends upon status)
36
43
  #
44
+ INPUT_F=0
45
+ DEFAULT=1
46
+ PROMPT=2
47
+
37
48
  ISSUE_FIELDS = {
38
- "title" => ["gets.chomp", "Short description of the issue"],
39
- "status" => ["'open'", ""],
40
- "created" => ["Date.today", ""],
41
- "component" => ["gets.chomp", "Component affected by the issue"],
42
- "priority" => ["get_int", "Priority (an integer number, e.g., from 1 to 5)"],
43
- "severity" => ["get_int", "Severity (an integer number, e.g., from 1 to 5)"],
44
- "points" => ["get_int", "Points (an integer estimating the difficulty of the issue)"],
45
- "type" => ["gets.chomp", "Type (e.g., story, task, bug, refactoring)"],
46
- "description" => ["get_lines", "Longer description (terminate with '.')"]
49
+ "title" => ["gets.chomp", "'title'", "Short description of the issue"],
50
+ "status" => ["", "'open'", ""],
51
+ "created" => ["", "Date.today", ""],
52
+ "component" => ["gets.chomp", "''", "Component affected by the issue"],
53
+ "priority" => ["get_int", "3", "Priority (an integer number, e.g., from 1 to 5)"],
54
+ "severity" => ["get_int", "3", "Severity (an integer number, e.g., from 1 to 5)"],
55
+ "points" => ["get_int", "5", "Points (an integer estimating difficulty of fix)"],
56
+ "type" => ["gets.chomp", "'bug'", "Type (e.g., story, task, bug, refactoring)"],
57
+ "description" => ["get_lines", "''", "Longer description (terminate with '.')"]
47
58
  }
48
59
 
49
60
  # which fields go to the report and formatting options
50
61
  REPORT_FIELDS = {
51
62
  "status" => "%-10s",
52
- "type" => "%-10s",
63
+ "type" => "%-12s",
53
64
  "priority" => "%8s",
54
65
  "severity" => "%8s",
55
66
  "created" => "%-10s",
56
- "title" => "%-32s"
67
+ "title" => "%-30s"
57
68
  }
58
69
 
59
70
  # these keep the actual values
@@ -61,13 +72,15 @@ module Beastie
61
72
  # the filename, after the issue has been saved or if it has been loaded
62
73
  attr_reader :filename
63
74
 
64
- # interactively ask from command line all fields specified in ISSUE_FIELDS
65
- def ask
75
+ def initialize
66
76
  @issue = Hash.new
77
+ end
67
78
 
79
+ # interactively ask from command line all fields specified in ISSUE_FIELDS
80
+ def ask
68
81
  ISSUE_FIELDS.keys.each do |key|
69
- puts "#{ISSUE_FIELDS[key][1]}: " if ISSUE_FIELDS[key][1] != ""
70
- @issue[key] = (eval ISSUE_FIELDS[key][0]) || ""
82
+ puts "#{ISSUE_FIELDS[key][PROMPT]}: " if ISSUE_FIELDS[key][PROMPT] != ""
83
+ @issue[key] = (eval ISSUE_FIELDS[key][INPUT_F]) || (eval ISSUE_FIELDS[key][DEFAULT])
71
84
  end
72
85
  end
73
86
 
@@ -97,6 +110,12 @@ module Beastie
97
110
  Dir.glob('*.{yml,yaml}')[n - 1]
98
111
  end
99
112
 
113
+ # count all issues in current directory
114
+ # to get the maximum ID
115
+ def self.count
116
+ Dir.glob('*.{yml,yaml}').size
117
+ end
118
+
100
119
  # list all issues in current directory
101
120
  def self.list
102
121
  # print header
@@ -120,6 +139,15 @@ module Beastie
120
139
  end
121
140
  end
122
141
 
142
+ # initialize all fields with the default values
143
+ # (and set title to the argument)
144
+ def set_fields title
145
+ ISSUE_FIELDS.keys.each do |k|
146
+ @issue[k] = eval(ISSUE_FIELDS[k][DEFAULT])
147
+ end
148
+ @issue['title'] = title
149
+ end
150
+
123
151
  private
124
152
 
125
153
  # read n-lines (terminated by a ".")
@@ -1,3 +1,3 @@
1
1
  module Beastie
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/beastie.rb CHANGED
@@ -44,21 +44,61 @@ module Beastie
44
44
  case command
45
45
 
46
46
  when "new"
47
+ if args.size != 0
48
+ puts "beastie error: too many arguments.\n"
49
+ help
50
+ exit 1
51
+ end
52
+
47
53
  issue = Issue.new
48
54
  issue.ask
49
55
  issue.save
50
56
 
51
57
  when "edit"
58
+ if args.size != 1 or not digits_only(args[0]) or args[0].to_i > Issue.count
59
+ puts "beastie error: please specify an issue.\n\n"
60
+ help
61
+ exit 1
62
+ end
63
+
52
64
  issue_no = args[0].to_i
53
65
  shell_editor = `echo ${EDITOR}`.chomp
54
66
  editor = shell_editor == "" ? EDITOR : shell_editor
55
67
  system("#{editor} #{Issue.filename issue_no}")
56
68
 
69
+ when "nedit"
70
+ title = args.join(" ") # get all arguments (so that no " are necessary)
71
+ if title == ""
72
+ puts "beastie error: please specify the title of the issue.\n"
73
+ help
74
+ exit 1
75
+ end
76
+
77
+ issue = Issue.new
78
+ issue.set_fields title
79
+ issue.save
80
+
81
+ shell_editor = `echo ${EDITOR}`.chomp
82
+ editor = shell_editor == "" ? EDITOR : shell_editor
83
+ system("#{editor} #{issue.filename}")
84
+
57
85
  when "show"
86
+ if args.size != 1 or not digits_only(args[0]) or args[0].to_i > Issue.count
87
+ puts "beastie error: please specify an issue.\n"
88
+ help
89
+ exit 1
90
+ end
91
+
58
92
  issue_no = args[0].to_i
59
93
  system("cat #{Issue.filename issue_no}")
60
94
 
61
95
  when "change"
96
+ if args.size != 3 or not digits_only(args[0]) or args[0].to_i > Issue.count
97
+ puts "beastie error: could not parse command line.\n"
98
+ help
99
+ exit 1
100
+ end
101
+
62
102
  issue_no = args[0].to_i
63
103
  field = args[1]
64
104
  value = args[2]
@@ -68,6 +108,12 @@ module Beastie
68
108
  issue.save
69
109
 
70
110
  when "close"
111
+ if args.size != 1 or not digits_only(args[0]) or args[0].to_i > Issue.count
112
+ puts "beastie error: please specify an issue.\n"
113
+ help
114
+ exit 1
115
+ end
116
+
71
117
  issue_no = args[0].to_i
72
118
  issue = Issue.new
73
119
  issue.load(Issue.filename issue_no)
@@ -92,19 +138,25 @@ module Beastie
92
138
  private
93
139
 
94
140
  def self.help
95
- puts "beastie command args"
141
+ puts "beastie <command> [<args>]"
96
142
  puts ""
97
143
  puts "A simple command-line bug-tracking system"
98
144
  puts ""
99
145
  puts "Commands:"
100
- puts " new create a new issue in current directory"
101
- puts " list list all issues stored in current directory"
102
- puts " edit N edit issue with id N (where N is the output of the list command)"
103
- puts " show N show issue with id N (where N is the output of the list command)"
104
- puts " change N f v change value of field 'f' to 'v' in id N"
105
- puts " close N shortcut for 'change N status closed'"
106
- puts " version print version number"
146
+ puts " new create a new issue in current directory"
147
+ puts " nedit title create an issue template and edit it with default editor"
148
+ puts " list list all issues stored in current directory"
149
+ puts " edit N edit issue with id N (where N is the output of the list command)"
150
+ puts " show N show issue with id N (where N is the output of the list command)"
151
+ puts " change N f v change value of field 'f' to 'v' in id N"
152
+ puts " close N shortcut for 'change N status closed'"
153
+ puts " version print version number"
107
154
  end
108
155
 
156
+ # check if str is composed by digits only
157
+ def self.digits_only str
158
+ str.each_char.map { |x| x >= '0' and x <= '9'}.all?
159
+ end
109
160
  end
161
+
110
162
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beastie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adolfo Villafiorita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-26 00:00:00.000000000 Z
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler