habits 0.1.1 → 0.1.2

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.
@@ -26,7 +26,8 @@ sub.register('delete', ['TITLE'], 'Delete habit.') do |title|
26
26
  puts "#{h.title} deleted."
27
27
  end
28
28
 
29
- sub.register('create', ['TITLE','DAYS'], 'Create a new habit.') do |title, days|
29
+ sub.register('create', ['TITLE','DAYS'],
30
+ 'Create a new habit. DAYS is comma separated list of Mon,Tue,Wed..') do |title, days|
30
31
  Habits::Habit.new(title, days.split(',')).save
31
32
  puts "Habit \"#{title}\" created."
32
33
  end
@@ -45,7 +46,10 @@ sub.register('list', [], 'List habits.') do
45
46
  on_hold = Habits::Habit.all_on_hold
46
47
 
47
48
  if on_hold.size > 0
48
- puts "\nOn Hold: #{on_hold.map{|h| h.title}.join(', ')}.\n"
49
+ puts "\nOn Hold:\n--------"
50
+ on_hold.each do |habit|
51
+ puts "* #{habit.title}"
52
+ end
49
53
  end
50
54
 
51
55
  puts "\nWeek #{Date.today.cweek} | Total #{Habits::Habit.all.size} habits "+
@@ -124,7 +128,12 @@ sub.register('unhold', ['TITLE'], 'Unhold a habit.') do |title|
124
128
  puts "Habit \"#{title}\" is not on hold anymore."
125
129
  end
126
130
 
131
+ sub.register('help', [], 'See the list of commands.') do
132
+ sub.help
133
+ end
127
134
 
128
- sub.default = 'list'
135
+ sub.default do
136
+ puts "Use 'habits help' to see the list of commands. "
137
+ end
129
138
 
130
139
  sub.parse
@@ -38,9 +38,12 @@ class Subcommand
38
38
  end
39
39
  end
40
40
 
41
+ attr_accessor :auto_help
42
+
41
43
  def initialize
42
44
  @default = nil
43
45
  @subs = {}
46
+ @auto_help = false
44
47
  end
45
48
 
46
49
  # Register a command with name, arguments, description, and block (blk).
@@ -71,14 +74,18 @@ class Subcommand
71
74
 
72
75
  sub = @subs[args.shift]
73
76
 
74
- help and return if sub.nil?
77
+ if sub.nil?
78
+ puts "Unknown command."
79
+ help if auto_help
80
+ return
81
+ end
75
82
 
76
83
  begin
77
84
  sub.parse(args)
78
85
  sub.call
79
86
  rescue Exception => e
80
87
  puts e.message
81
- help
88
+ help if auto_help
82
89
  end
83
90
  end
84
91
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: habits
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Antti Hakala
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-13 00:00:00 +02:00
18
+ date: 2011-04-14 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  requirements: []
72
72
 
73
73
  rubyforge_project:
74
- rubygems_version: 1.3.7
74
+ rubygems_version: 1.5.0
75
75
  signing_key:
76
76
  specification_version: 3
77
77
  summary: A habit tracker.