posto 0.3.3 → 0.3.4
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.
- data/README.md +12 -0
- data/lib/posto/application.rb +5 -0
- data/lib/posto/arguments.rb +1 -13
- data/lib/posto/help.md +26 -0
- data/lib/posto/help.rb +54 -0
- data/test/arguments_test.rb +0 -13
- data/test/help_test.rb +46 -0
- metadata +7 -3
data/README.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
Sort your todo list from the command line.
|
4
4
|
|
5
|
+
## Tutorial
|
6
|
+
|
7
|
+
After adding `gem "posto"` to your Gemfile, `bundle install`
|
8
|
+
|
9
|
+
To initialize a posto file, `posto init`
|
10
|
+
|
11
|
+
To add a task, `posto add "an example task"`
|
12
|
+
|
13
|
+
To see current tasks, `posto`
|
14
|
+
|
15
|
+
To see a full list of commands, click [here](https://github.com/mattraibert/posto/blob/master/lib/posto/help.md).
|
16
|
+
|
5
17
|
## Naming
|
6
18
|
|
7
19
|
Posto is named for [Del Posto](http://www.delposto.com/) in New York City -- a restaurant that has been on my todo list for quite a while.
|
data/lib/posto/application.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'posto/list'
|
2
2
|
require 'posto/file'
|
3
|
+
require 'posto/help'
|
3
4
|
|
4
5
|
module Posto
|
5
6
|
class Application
|
@@ -14,6 +15,10 @@ module Posto
|
|
14
15
|
@todos = todos
|
15
16
|
end
|
16
17
|
|
18
|
+
def help
|
19
|
+
@io.puts Posto::Help.help_text
|
20
|
+
end
|
21
|
+
|
17
22
|
def run
|
18
23
|
@io.puts send(@arguments.command, *@arguments.params)
|
19
24
|
end
|
data/lib/posto/arguments.rb
CHANGED
@@ -13,19 +13,7 @@ module Posto
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def filename
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def read_flag(flag)
|
20
|
-
filename_index = @args.index(flag)
|
21
|
-
unless filename_index.nil?
|
22
|
-
@args.delete_at(filename_index)
|
23
|
-
@args.delete_at(filename_index)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def to_s
|
28
|
-
@args.inspect
|
16
|
+
"posto.md"
|
29
17
|
end
|
30
18
|
end
|
31
19
|
end
|
data/lib/posto/help.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
### List Commands
|
2
|
+
|
3
|
+
`init`: create a 'posto.md' file in the working directory.
|
4
|
+
|
5
|
+
`list`, `todos`, `[default]`: display the todo list.
|
6
|
+
|
7
|
+
`sort`: ask the user about priorities to sort todos.
|
8
|
+
|
9
|
+
`resort`: reset sort order and sort again (can be time consuming).
|
10
|
+
|
11
|
+
|
12
|
+
### Single Todo Commands
|
13
|
+
|
14
|
+
`add '<todo>'`: add <todo> unsorted to the bottom of the todo list.
|
15
|
+
|
16
|
+
`start '<todo>'`: add, sort and commit with a message based on <todo>.
|
17
|
+
|
18
|
+
`done [n = 1]`, `delete [n]`: remove the nth todo from the list.
|
19
|
+
|
20
|
+
`commit [n]`: remove the nth todo; commit with a message based on the todo.
|
21
|
+
|
22
|
+
`do`, `top`: displays the top todo.
|
23
|
+
|
24
|
+
`do [n]`, `top [n]`: move the nth todo to the top.
|
25
|
+
|
26
|
+
`unsort [n]`: unsort the nth todo and place it at the bottom.
|
data/lib/posto/help.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Posto
|
2
|
+
module Help
|
3
|
+
class << self
|
4
|
+
def help_text
|
5
|
+
format(parse(read))
|
6
|
+
end
|
7
|
+
|
8
|
+
def read
|
9
|
+
lines = ::File.read("#{::File.dirname(__FILE__)}/help.md").lines
|
10
|
+
lines.map { |line| line.chomp }.reject(&:empty?).map { |line| line.gsub /(### |`)/, "" }
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse(md_file)
|
14
|
+
md_file.map { |x| x.split(": ") }.inject({}) do |memo, o|
|
15
|
+
memo[:title] = o.first if o.size == 1
|
16
|
+
memo[memo[:title]] ||= {}
|
17
|
+
memo[memo[:title]][o.first]= o.last if o.size == 2
|
18
|
+
memo
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def format(hash)
|
23
|
+
hash.delete(:title)
|
24
|
+
hash.map { |title, commands| format_list(commands, title) }.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def format_list(commands, title)
|
28
|
+
"\n#{title}:\n#{format_commands(commands)}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def format_commands(commands)
|
32
|
+
commands.map do |command, definition|
|
33
|
+
format_command_definition(command, definition)
|
34
|
+
end.join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_command_definition(command, definition)
|
38
|
+
aliases = command.split(', ')
|
39
|
+
command = aliases.first
|
40
|
+
aliases = aliases[1..-1]
|
41
|
+
(["#{format_command command}#{definition}"] +
|
42
|
+
aliases.map { |command_alias| format_alias(command_alias, command) }).join("\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
def format_alias(command_alias, alias_for)
|
46
|
+
"#{format_command command_alias}alias for '#{alias_for}'"
|
47
|
+
end
|
48
|
+
|
49
|
+
def format_command(command_alias)
|
50
|
+
' ' * 3 + command_alias.ljust(15)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/test/arguments_test.rb
CHANGED
@@ -2,13 +2,6 @@ require 'test_helper'
|
|
2
2
|
require 'posto/arguments'
|
3
3
|
|
4
4
|
class ArgumentsTest < MiniTest::Unit::TestCase
|
5
|
-
def test_read_flag
|
6
|
-
assert_equal("blah.md", Posto::Arguments.new(%w(-f blah.md)).read_flag("-f"))
|
7
|
-
assert_equal("blah.md", Posto::Arguments.new(%w(sort -f blah.md)).read_flag("-f"))
|
8
|
-
assert_equal("blah.md", Posto::Arguments.new(%w(done 5 -f blah.md)).read_flag("-f"))
|
9
|
-
assert_equal("blah.md", Posto::Arguments.new(%w(-f blah.md done 5)).read_flag("-f"))
|
10
|
-
end
|
11
|
-
|
12
5
|
def test_command
|
13
6
|
assert_equal("list", Posto::Arguments.new([]).command)
|
14
7
|
assert_equal("sort", Posto::Arguments.new(%w(sort)).command)
|
@@ -20,10 +13,4 @@ class ArgumentsTest < MiniTest::Unit::TestCase
|
|
20
13
|
assert_equal([], Posto::Arguments.new(%w(sort)).params)
|
21
14
|
assert_equal(["5"], Posto::Arguments.new(%w(done 5)).params)
|
22
15
|
end
|
23
|
-
|
24
|
-
def test_flag_deletes_flag
|
25
|
-
args = %w(-f blah.md done 5)
|
26
|
-
Posto::Arguments.new(args).read_flag("-f")
|
27
|
-
assert_equal(%w(done 5), args)
|
28
|
-
end
|
29
16
|
end
|
data/test/help_test.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'posto/help'
|
3
|
+
|
4
|
+
class HelpTest < MiniTest::Unit::TestCase
|
5
|
+
def test_command_without_aliases
|
6
|
+
assert_equal " init create a 'posto.md' file in the working directory.",
|
7
|
+
Posto::Help.format_command_definition("init", "create a 'posto.md' file in the working directory.")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_command_with_aliases
|
11
|
+
expected = <<EOF.chomp
|
12
|
+
list display the todo list.
|
13
|
+
todos alias for 'list'
|
14
|
+
[default] alias for 'list'
|
15
|
+
EOF
|
16
|
+
assert_equal expected, Posto::Help.format_command_definition("list, todos, [default]", "display the todo list.")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_help
|
20
|
+
help_text = <<EOF.chomp
|
21
|
+
|
22
|
+
List Commands:
|
23
|
+
init create a 'posto.md' file in the working directory.
|
24
|
+
list display the todo list.
|
25
|
+
todos alias for 'list'
|
26
|
+
[default] alias for 'list'
|
27
|
+
sort ask the user about priorities to sort todos.
|
28
|
+
resort reset sort order and sort again (can be time consuming).
|
29
|
+
|
30
|
+
Single Todo Commands:
|
31
|
+
add '<todo>' add <todo> unsorted to the bottom of the todo list.
|
32
|
+
start '<todo>' add, sort and commit with a message based on <todo>.
|
33
|
+
done [n = 1] remove the nth todo from the list.
|
34
|
+
delete [n] alias for 'done [n = 1]'
|
35
|
+
commit [n] remove the nth todo; commit with a message based on the todo.
|
36
|
+
do displays the top todo.
|
37
|
+
top alias for 'do'
|
38
|
+
do [n] move the nth todo to the top.
|
39
|
+
top [n] alias for 'do [n]'
|
40
|
+
unsort [n] unsort the nth todo and place it at the bottom.
|
41
|
+
EOF
|
42
|
+
assert_equal(help_text, Posto::Help.help_text)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -57,8 +57,10 @@ files:
|
|
57
57
|
- lib/posto/monkeypatch_array.rb
|
58
58
|
- lib/posto/application.rb
|
59
59
|
- lib/posto/list.rb
|
60
|
+
- lib/posto/help.rb
|
60
61
|
- lib/posto/todo.rb
|
61
62
|
- lib/posto/file.rb
|
63
|
+
- lib/posto/help.md
|
62
64
|
- lib/posto/arguments.rb
|
63
65
|
- lib/posto/human_comparison.rb
|
64
66
|
- lib/posto.rb
|
@@ -68,6 +70,7 @@ files:
|
|
68
70
|
- test/application_test.rb
|
69
71
|
- test/monkeypatch_array_test.rb
|
70
72
|
- test/todo_test.rb
|
73
|
+
- test/help_test.rb
|
71
74
|
homepage: http://github.com/mattraibert/posto
|
72
75
|
licenses:
|
73
76
|
- GPLv3
|
@@ -83,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
86
|
version: '0'
|
84
87
|
segments:
|
85
88
|
- 0
|
86
|
-
hash:
|
89
|
+
hash: 3524327587989594064
|
87
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
91
|
none: false
|
89
92
|
requirements:
|
@@ -103,3 +106,4 @@ test_files:
|
|
103
106
|
- test/application_test.rb
|
104
107
|
- test/monkeypatch_array_test.rb
|
105
108
|
- test/todo_test.rb
|
109
|
+
- test/help_test.rb
|