hackpad-cli 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +8 -0
- data/README.md +8 -2
- data/hackpad-cli.gemspec +1 -0
- data/lib/hackpad/cli/client.rb +26 -9
- data/lib/hackpad/cli/config.rb +18 -14
- data/lib/hackpad/cli/pad.rb +27 -12
- data/lib/hackpad/cli/padlist.rb +19 -7
- data/lib/hackpad/cli/plain_colors.rb +8 -0
- data/lib/hackpad/cli/runner.rb +5 -0
- data/lib/hackpad/cli/store.rb +11 -8
- data/lib/hackpad/cli/version.rb +1 -1
- data/spec/lib/hackpad/cli/client_spec.rb +111 -3
- data/spec/lib/hackpad/cli/config_spec.rb +47 -0
- data/spec/lib/hackpad/cli/pad_spec.rb +4 -4
- data/spec/lib/hackpad/cli/runner_spec.rb +12 -11
- data/spec/lib/hackpad/cli/store_spec.rb +40 -14
- data/spec/spec_helper.rb +3 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7daab4b137edd9a8b347ea91aa5f3b2b274d62cf
|
4
|
+
data.tar.gz: 0a6ea6f6ff546036118c9a92e5517e2f590e9c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0888040ce658299976f0d38216665e7839df805a7c24e581cfce30623d91758d3243a275c9e84cb1f252e7c66e8e501132b709dd670ba942e98f5a560a9b1763
|
7
|
+
data.tar.gz: c5d33ee8c511411f82705a8e5a7c76f71956dffd7024f90388b3b99f7397b0c5ac1c90ecae7afd1fb56e90a647dde505d1bf38770f4b9db8518d2949bd53a252
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Hackpad-cli changelog
|
2
2
|
==========================
|
3
3
|
|
4
|
+
v0.0.7 - 2014-05-15
|
5
|
+
-------------
|
6
|
+
|
7
|
+
- add a `cached_at` value in metadata, visible in the `show` command
|
8
|
+
- fix `info` to display guest policy properly
|
9
|
+
- add a `check` command to check if there are new pads and dcide to refresh or not
|
10
|
+
- whole lot of more tests
|
11
|
+
|
4
12
|
v0.0.6 - 2014-05-04
|
5
13
|
------------
|
6
14
|
|
data/README.md
CHANGED
@@ -15,7 +15,12 @@ It uses Hackpad REST API 1.0 https://hackpad.com/fQD2DRz22Wf and was tested with
|
|
15
15
|
Initially this tool was created to overcome the frustration of the md export of pads,
|
16
16
|
because we need to copy them to other places sometimes. Proper markdown would be appreciated. It does that by transforming the html in markdown with the https://github.com/xijo/reverse_markdown gem.
|
17
17
|
|
18
|
-
|
18
|
+
Offline hackpad reading
|
19
|
+
-----------------------
|
20
|
+
|
21
|
+
It felt right to cache the pads content and list because then we can browse and search in the whole workspace very fast. So by default the `list`, `show` and `info` are cached unless you pass the `-r` option at the end of the commandline. Note that the longest is the `list` because the API don't provide pads titles, so `hpcli list` actually downloads the whole list of the pads in txt format. But it makes the `info` and the `show` very fast after that.
|
22
|
+
|
23
|
+
The side effect is that it provides the ability to just refresh the list of pads with `hpcli list`, and it will cache the text version of each pad locally. Then you can `hpcli show <xxx>` without hitting the api.
|
19
24
|
|
20
25
|
Installation
|
21
26
|
------------------
|
@@ -35,6 +40,7 @@ Usage
|
|
35
40
|
|
36
41
|
```
|
37
42
|
Commands:
|
43
|
+
hpcli check # Checks differences between local cache and remote list.
|
38
44
|
hpcli help [COMMAND] # Describe available commands or one specific command
|
39
45
|
hpcli info [pad_id] # gets info for the pad <pad_id>.
|
40
46
|
hpcli list # Lists available pads.
|
@@ -64,7 +70,7 @@ Check the [Changelog](CHANGELOG.md) for past evolutions.
|
|
64
70
|
- <s>add freaking cool badges on the readme</s>
|
65
71
|
- <s>cache the pads list in a local storage</s>
|
66
72
|
- <s>have a choice to refresh cache</s>
|
67
|
-
- display cached date in output
|
73
|
+
- <s>display cached date in output</s>
|
68
74
|
- write proper tests
|
69
75
|
- for v0.2.0
|
70
76
|
- add commands for creating a new pad, linked to $EDITOR
|
data/hackpad-cli.gemspec
CHANGED
data/lib/hackpad/cli/client.rb
CHANGED
@@ -11,7 +11,8 @@ module Hackpad
|
|
11
11
|
module Cli
|
12
12
|
class Client
|
13
13
|
|
14
|
-
def initialize(options)
|
14
|
+
def initialize(options, output=STDOUT)
|
15
|
+
@output = output
|
15
16
|
@options = options
|
16
17
|
Store.prepare @options
|
17
18
|
@config = Config.load @options
|
@@ -25,18 +26,29 @@ module Hackpad
|
|
25
26
|
def search(term,start=0)
|
26
27
|
payload = Api.search(term,start)
|
27
28
|
payload.each do |a|
|
28
|
-
puts "#{(@config['site'] + '/') if @options[
|
29
|
-
puts " #{extract a['snippet']}"
|
29
|
+
@output.puts "#{(@config['site'] + '/') if @options[:urls]}#{a['id'].bold} - #{unescape(a['title']).yellow}"
|
30
|
+
@output.puts " #{extract a['snippet']}"
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
34
|
def list
|
34
|
-
|
35
|
-
|
36
|
-
"#{(@config['site'] + '/') if @options['urls']}#{pad.id} - #{pad.title}"
|
35
|
+
@output.puts Padlist.get_list(@options['refresh']).map { |pad|
|
36
|
+
padline pad
|
37
37
|
}
|
38
38
|
end
|
39
39
|
|
40
|
+
def check
|
41
|
+
@output.puts "New pads:"
|
42
|
+
padlist = Padlist.check_list.map
|
43
|
+
if padlist.count == 0
|
44
|
+
@output.puts "There is no new pad."
|
45
|
+
else
|
46
|
+
@output.puts padlist.map { |pad|
|
47
|
+
padline pad
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
def info(id)
|
41
53
|
pad = Pad.new id
|
42
54
|
pad.load 'txt'
|
@@ -47,6 +59,7 @@ module Hackpad
|
|
47
59
|
table "Lines", "#{pad.lines}"
|
48
60
|
table "Guest Policy", "#{pad.guest_policy}"
|
49
61
|
table "Moderated", "#{pad.moderated}"
|
62
|
+
table "Cached", "#{pad.cached_at || 'unknown'}"
|
50
63
|
end
|
51
64
|
|
52
65
|
def show(id,format)
|
@@ -54,14 +67,18 @@ module Hackpad
|
|
54
67
|
pad = Pad.new id
|
55
68
|
pad.load ext
|
56
69
|
if format == 'md'
|
57
|
-
puts ReverseMarkdown.convert(pad.content, github_flavored: true)
|
70
|
+
@output.puts ReverseMarkdown.convert(pad.content, github_flavored: true)
|
58
71
|
else
|
59
|
-
puts pad.content
|
72
|
+
@output.puts pad.content
|
60
73
|
end
|
61
74
|
end
|
62
75
|
|
63
76
|
private
|
64
77
|
|
78
|
+
def padline(pad)
|
79
|
+
"#{(@config['site'] + '/') if @options[:urls]}#{pad.id} - #{pad.title}"
|
80
|
+
end
|
81
|
+
|
65
82
|
def unescape(s)
|
66
83
|
CGI.unescapeHTML s
|
67
84
|
end
|
@@ -71,7 +88,7 @@ module Hackpad
|
|
71
88
|
end
|
72
89
|
|
73
90
|
def table(key,value)
|
74
|
-
printf "%-20s %s\n", key, value
|
91
|
+
@output.printf "%-20s %s\n", key, value
|
75
92
|
end
|
76
93
|
|
77
94
|
end
|
data/lib/hackpad/cli/config.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
1
3
|
module Hackpad
|
2
4
|
module Cli
|
3
5
|
module Config
|
4
6
|
extend self
|
5
7
|
|
6
|
-
def load(options)
|
8
|
+
def load(options, input=STDIN, output=STDOUT)
|
9
|
+
@input = input
|
10
|
+
@output = output
|
7
11
|
configdir = options[:configdir]
|
8
12
|
configfile = File.join(configdir, "#{options[:workspace]}.yml")
|
9
13
|
# temporary migration path
|
@@ -11,27 +15,27 @@ module Hackpad
|
|
11
15
|
FileUtils.mv File.join(configdir, "config.yml"), configfile
|
12
16
|
end
|
13
17
|
if !Dir.exists?(configdir) || !File.exists?(configfile)
|
14
|
-
setup configfile
|
18
|
+
setup configfile, input, output
|
15
19
|
end
|
16
20
|
YAML::load_file configfile
|
17
21
|
end
|
18
22
|
|
19
23
|
private
|
20
24
|
|
21
|
-
def setup(configfile)
|
25
|
+
def setup(configfile, input=STDIN, output=STDOUT)
|
22
26
|
config = {}
|
23
27
|
FileUtils.mkdir_p File.dirname(configfile)
|
24
|
-
puts "We need first to initialize your hackpad-cli configuration.".blue
|
25
|
-
puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/".light_blue
|
26
|
-
print "What is your Client ID? "
|
27
|
-
|
28
|
-
|
29
|
-
print "What is your Secret Key? "
|
30
|
-
|
31
|
-
config['secret'] =
|
32
|
-
print "What is the URI of your pad? "
|
33
|
-
|
34
|
-
config['site'] =
|
28
|
+
output.puts "We need first to initialize your hackpad-cli configuration.".blue
|
29
|
+
output.puts "Please gather your information from https://<subdomain>.hackpad.com/ep/account/settings/".light_blue
|
30
|
+
output.print "What is your Client ID? "
|
31
|
+
config['client_id'] = input.gets.chomp
|
32
|
+
output.flush
|
33
|
+
output.print "What is your Secret Key? "
|
34
|
+
output.flush
|
35
|
+
config['secret'] = input.gets.chomp
|
36
|
+
output.print "What is the URI of your pad? "
|
37
|
+
output.flush
|
38
|
+
config['site'] = input.gets.chomp
|
35
39
|
File.open(configfile, "w") do |f|
|
36
40
|
f.write YAML::dump(config)
|
37
41
|
end
|
data/lib/hackpad/cli/pad.rb
CHANGED
@@ -10,7 +10,7 @@ module Hackpad
|
|
10
10
|
|
11
11
|
class Pad
|
12
12
|
|
13
|
-
attr_reader :id, :content, :guest_policy, :moderated
|
13
|
+
attr_reader :id, :content, :guest_policy, :moderated, :cached_at
|
14
14
|
|
15
15
|
def initialize(id)
|
16
16
|
@id = id
|
@@ -31,21 +31,36 @@ module Hackpad
|
|
31
31
|
def load(ext, refresh=false)
|
32
32
|
raise UnknownFormat unless FORMATS.include? ext
|
33
33
|
raise UndefinedPad unless @id
|
34
|
-
if refresh or !Store.exists? ext, id
|
35
|
-
|
36
|
-
Store.save self, ext
|
37
|
-
options = Api.read_options id
|
38
|
-
@guest_policy = options['guestPolicy']
|
39
|
-
@moderated = !!options['isModerated']
|
40
|
-
Store.save_meta @id, options
|
34
|
+
if refresh or !Store.exists? ext, @id
|
35
|
+
load_from_api ext
|
41
36
|
else
|
42
|
-
|
43
|
-
options = Store.read_options id
|
44
|
-
@guest_policy = options['guestPolicy']
|
45
|
-
@moderated = !!options['isModerated']
|
37
|
+
load_from_cache ext
|
46
38
|
end
|
47
39
|
end
|
48
40
|
|
41
|
+
def load_from_api(ext)
|
42
|
+
@content = Api.read @id, ext
|
43
|
+
Store.save self, ext
|
44
|
+
options = Api.read_options @id
|
45
|
+
@guest_policy = options['options']['guestPolicy']
|
46
|
+
@moderated = !!options['options']['isModerated']
|
47
|
+
options['cached_at'] = Time.now
|
48
|
+
@cached_at = options['cached_at']
|
49
|
+
Store.save_meta @id, options
|
50
|
+
end
|
51
|
+
|
52
|
+
def load_from_cache(ext)
|
53
|
+
@content = Store.read @id, ext
|
54
|
+
options = Store.read_options @id
|
55
|
+
@guest_policy = options['options']['guestPolicy']
|
56
|
+
@moderated = !!options['options']['isModerated']
|
57
|
+
@cached_at = options['cached_at']
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_cached?
|
61
|
+
Store.exists? 'meta', @id
|
62
|
+
end
|
63
|
+
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/lib/hackpad/cli/padlist.rb
CHANGED
@@ -5,26 +5,38 @@ require_relative "pad"
|
|
5
5
|
|
6
6
|
module Hackpad
|
7
7
|
module Cli
|
8
|
-
|
8
|
+
module Padlist
|
9
|
+
extend self
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(refresh=false)
|
11
|
+
def get_list(refresh=false)
|
12
|
+
all = []
|
13
13
|
if refresh or !Store.exists? "padlist"
|
14
14
|
print "Refreshing "
|
15
15
|
list = Api.list
|
16
|
-
@all = []
|
17
16
|
list.each do |a|
|
18
17
|
print "."
|
19
18
|
pad = Pad.new a
|
20
19
|
pad.load 'txt', refresh
|
21
|
-
|
20
|
+
all << OpenStruct.new( id: a, title: pad.title )
|
22
21
|
end
|
23
22
|
puts " all done."
|
24
23
|
Store.save_list all
|
25
24
|
else
|
26
|
-
|
25
|
+
all = Store.read_list
|
26
|
+
end
|
27
|
+
all
|
28
|
+
end
|
29
|
+
|
30
|
+
def check_list
|
31
|
+
all = []
|
32
|
+
list = Api.list
|
33
|
+
list.each do |a|
|
34
|
+
pad = Pad.new a
|
35
|
+
if !pad.is_cached?
|
36
|
+
all << OpenStruct.new( id: a, title: pad.title )
|
37
|
+
end
|
27
38
|
end
|
39
|
+
all
|
28
40
|
end
|
29
41
|
|
30
42
|
end
|
@@ -1,5 +1,13 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
1
3
|
class String
|
2
4
|
def colorize(params)
|
3
5
|
self
|
4
6
|
end
|
5
7
|
end
|
8
|
+
|
9
|
+
String.send(:remove_const, :COLORS)
|
10
|
+
String.send(:remove_const, :MODES)
|
11
|
+
String.send(:remove_const, :REGEXP_PATTERN)
|
12
|
+
String.send(:remove_const, :COLOR_OFFSET)
|
13
|
+
String.send(:remove_const, :BACKGROUND_OFFSET)
|
data/lib/hackpad/cli/runner.rb
CHANGED
@@ -47,6 +47,11 @@ module Hackpad
|
|
47
47
|
Hackpad::Cli::Client.new(options).list
|
48
48
|
end
|
49
49
|
|
50
|
+
desc "check", "Checks differences between local cache and remote list."
|
51
|
+
def check
|
52
|
+
Hackpad::Cli::Client.new(options).check
|
53
|
+
end
|
54
|
+
|
50
55
|
desc "info [pad_id]", "gets info for the pad <pad_id>."
|
51
56
|
def info(pad)
|
52
57
|
Hackpad::Cli::Client.new(options).info pad
|
data/lib/hackpad/cli/store.rb
CHANGED
@@ -8,12 +8,15 @@ module Hackpad
|
|
8
8
|
extend self
|
9
9
|
|
10
10
|
def prepare(config)
|
11
|
-
@refresh = config[
|
12
|
-
|
13
|
-
@pads_dir = File.join(
|
14
|
-
@list_cache = File.join(
|
15
|
-
|
16
|
-
|
11
|
+
@refresh = config[:refresh]
|
12
|
+
dir = File.join(config[:configdir], config[:workspace])
|
13
|
+
@pads_dir = File.join(dir, 'pads')
|
14
|
+
@list_cache = File.join(dir, 'pads.list')
|
15
|
+
prepare_dirs @pads_dir
|
16
|
+
end
|
17
|
+
|
18
|
+
def prepare_dirs(base)
|
19
|
+
(Hackpad::Cli::FORMATS + ['meta']).each { |f| FileUtils.mkdir_p File.join(base, f) }
|
17
20
|
end
|
18
21
|
|
19
22
|
def exists?(*path)
|
@@ -52,8 +55,8 @@ module Hackpad
|
|
52
55
|
|
53
56
|
def read_list
|
54
57
|
File.read(File.join(@pads_dir, 'padlist')).lines.reduce([]) { |a,line|
|
55
|
-
/(?<id>[a-zA-Z0-9]*) (?<title>.*)/ =~ line
|
56
|
-
a << OpenStruct.new( id: id, title: title )
|
58
|
+
/(?<id>[a-zA-Z0-9]*) (\[(?<cached_at>[-a-zA-Z0-9: ]*)\] )?(?<title>.*)/ =~ line
|
59
|
+
a << OpenStruct.new( id: id, title: title, cached_at: cached_at )
|
57
60
|
a
|
58
61
|
}
|
59
62
|
end
|
data/lib/hackpad/cli/version.rb
CHANGED
@@ -4,10 +4,118 @@ require 'spec_helper'
|
|
4
4
|
require "hackpad/cli/client"
|
5
5
|
|
6
6
|
describe Hackpad::Cli::Client do
|
7
|
+
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
8
|
+
let(:options) { { configdir: configdir, workspace: 'default' } }
|
9
|
+
|
10
|
+
describe ".new" do
|
11
|
+
before { Hackpad::Cli::Api.stub(:prepare) }
|
12
|
+
before { Hackpad::Cli::Store.stub(:prepare) }
|
13
|
+
before { Hackpad::Cli::Config.stub(:load) }
|
14
|
+
|
15
|
+
context "when default options are passed," do
|
16
|
+
let(:client) { Hackpad::Cli::Client.new options }
|
17
|
+
it { expect(client).to be_a Hackpad::Cli::Client }
|
18
|
+
context "when colorization is expected," do
|
19
|
+
it { expect("x".blue).to eq "\e[0;34;49mx\e[0m" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when plain text is required," do
|
24
|
+
context "when colorization is not expected," do
|
25
|
+
before { Hackpad::Cli::Client.new options.merge({plain: true}) }
|
26
|
+
after { load "colorize.rb" }
|
27
|
+
it { expect("x".blue).to eq "x" }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".search" do
|
33
|
+
before { Hackpad::Cli::Api.stub(:prepare) }
|
34
|
+
before { Hackpad::Cli::Store.stub(:prepare) }
|
35
|
+
before { Hackpad::Cli::Config.stub(:load).and_return({'site' => 'http://test.dev'}) }
|
36
|
+
before {
|
37
|
+
Hackpad::Cli::Api.stub(:search).with("xxx",0).and_return(
|
38
|
+
[ {
|
39
|
+
"title" => "xtitle",
|
40
|
+
"id" => "xxxxxx",
|
41
|
+
"snippet" => "context <b class=\"hit\">x</b> context"
|
42
|
+
} ]
|
43
|
+
)
|
44
|
+
}
|
45
|
+
context "when default options are used," do
|
46
|
+
let(:client) { Hackpad::Cli::Client.new options }
|
47
|
+
it {
|
48
|
+
expect(STDOUT).to receive(:puts).with("\e[1;39;49mxxxxxx\e[0m - \e[0;33;49mxtitle\e[0m")
|
49
|
+
expect(STDOUT).to receive(:puts).with(" context \e[1;36;49mx\e[0m context")
|
50
|
+
client.search "xxx"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
context "when options sets urls to true," do
|
54
|
+
let(:client) { Hackpad::Cli::Client.new options.merge({urls: true}) }
|
55
|
+
it {
|
56
|
+
expect(STDOUT).to receive(:puts).with("http://test.dev/\e[1;39;49mxxxxxx\e[0m - \e[0;33;49mxtitle\e[0m")
|
57
|
+
expect(STDOUT).to receive(:puts).with(" context \e[1;36;49mx\e[0m context")
|
58
|
+
client.search "xxx"
|
59
|
+
}
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".list" do
|
64
|
+
before { Hackpad::Cli::Api.stub(:prepare) }
|
65
|
+
before { Hackpad::Cli::Store.stub(:prepare) }
|
66
|
+
before { Hackpad::Cli::Config.stub(:load).and_return({'site' => 'http://test.dev'}) }
|
67
|
+
before { Hackpad::Cli::Padlist.stub(:get_list).and_return( [ OpenStruct.new( id: 'xxxxxx', title: 'xtitle' ) ] ) }
|
68
|
+
context "when default options are used," do
|
69
|
+
let(:client) { Hackpad::Cli::Client.new options }
|
70
|
+
it {
|
71
|
+
expect(STDOUT).to receive(:puts).with(["xxxxxx - xtitle"])
|
72
|
+
client.list
|
73
|
+
}
|
74
|
+
end
|
75
|
+
context "when options sets urls to true," do
|
76
|
+
let(:client) { Hackpad::Cli::Client.new options.merge({urls: true}) }
|
77
|
+
it {
|
78
|
+
expect(STDOUT).to receive(:puts).with(["http://test.dev/xxxxxx - xtitle"])
|
79
|
+
client.list
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe ".check" do
|
85
|
+
before { Hackpad::Cli::Api.stub(:prepare) }
|
86
|
+
before { Hackpad::Cli::Store.stub(:prepare) }
|
87
|
+
before { Hackpad::Cli::Config.stub(:load).and_return({'site' => 'http://test.dev'}) }
|
88
|
+
before { Hackpad::Cli::Padlist.stub(:check_list).and_return( [ OpenStruct.new( id: 'xxxxxx', title: 'xtitle' ) ] ) }
|
89
|
+
context "when default options are used," do
|
90
|
+
let(:client) { Hackpad::Cli::Client.new options }
|
91
|
+
it {
|
92
|
+
expect(STDOUT).to receive(:puts).with("New pads:")
|
93
|
+
expect(STDOUT).to receive(:puts).with(["xxxxxx - xtitle"])
|
94
|
+
client.check
|
95
|
+
}
|
96
|
+
end
|
97
|
+
context "when options sets urls to true," do
|
98
|
+
let(:client) { Hackpad::Cli::Client.new options.merge({urls: true}) }
|
99
|
+
it {
|
100
|
+
expect(STDOUT).to receive(:puts).with("New pads:")
|
101
|
+
expect(STDOUT).to receive(:puts).with(["http://test.dev/xxxxxx - xtitle"])
|
102
|
+
client.check
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe ".info" do
|
108
|
+
before { Hackpad::Cli::Api.stub(:prepare) }
|
109
|
+
before { Hackpad::Cli::Store.stub(:prepare) }
|
110
|
+
before { Hackpad::Cli::Config.stub(:load).and_return({'site' => 'http://test.dev'}) }
|
111
|
+
context "when unknown id is given" do
|
112
|
+
pending "todo"
|
113
|
+
end
|
114
|
+
context "when id is an existing pad" do
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
7
118
|
|
8
|
-
pending "Hackpad::Cli::Client.new"
|
9
|
-
pending "Hackpad::Cli::Client.search"
|
10
|
-
pending "Hackpad::Cli::Client.list"
|
11
119
|
pending "Hackpad::Cli::Client.info"
|
12
120
|
pending "Hackpad::Cli::Client.show"
|
13
121
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "hackpad/cli/config"
|
5
|
+
|
6
|
+
describe Hackpad::Cli::Config do
|
7
|
+
|
8
|
+
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
9
|
+
let(:configfile) { File.join(configdir, 'default.yml') }
|
10
|
+
let(:options) { { configdir: configdir, workspace: 'default' } }
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
FileUtils.mkdir_p configdir unless Dir.exists?(configdir)
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
FileUtils.rm configfile if File.exists? configfile
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".load" do
|
21
|
+
let(:config) { {'xx' => 'oo'} }
|
22
|
+
|
23
|
+
context "when there is no config file," do
|
24
|
+
it "calls for setup" do
|
25
|
+
subject.stub(:setup).with(configfile)
|
26
|
+
File.open(configfile, "w") do |f|
|
27
|
+
f.write YAML::dump(config)
|
28
|
+
end
|
29
|
+
expect(subject.load options).to eq config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".setup" do
|
36
|
+
context "when normal input is provided," do
|
37
|
+
let(:input) { StringIO.new }
|
38
|
+
let(:output) { StringIO.new }
|
39
|
+
it "handles setup interactively" do
|
40
|
+
input.stub(:gets).and_return("client_id","secret","site")
|
41
|
+
subject.send :setup, configfile, input, output
|
42
|
+
expect(File.read configfile).to eq "---\nclient_id: client_id\nsecret: secret\nsite: site\n"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -10,10 +10,10 @@ describe Hackpad::Cli::Pad do
|
|
10
10
|
|
11
11
|
before :each do
|
12
12
|
Hackpad::Cli::Api.stub(:read).with('123', 'txt').and_return("content\nand body")
|
13
|
-
Hackpad::Cli::Api.stub(:read_options).with('123').and_return({"success" => "true"})
|
13
|
+
Hackpad::Cli::Api.stub(:read_options).with('123').and_return({"success" => "true", "options" => {}})
|
14
14
|
options = {
|
15
|
-
|
16
|
-
|
15
|
+
configdir: File.expand_path('../../../../files', __FILE__),
|
16
|
+
workspace: 'default'
|
17
17
|
}
|
18
18
|
Hackpad::Cli::Store.prepare options
|
19
19
|
@pad = Hackpad::Cli::Pad.new "123"
|
@@ -21,7 +21,7 @@ describe Hackpad::Cli::Pad do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
after :each do
|
24
|
-
FileUtils.rm_rf File.expand_path('
|
24
|
+
FileUtils.rm_rf File.expand_path('../../../../files/default', __FILE__)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "creates a new pad object" do
|
@@ -6,43 +6,44 @@ require "hackpad/cli/client"
|
|
6
6
|
|
7
7
|
describe Hackpad::Cli::Runner do
|
8
8
|
|
9
|
+
let(:cli) { Hackpad::Cli::Runner.new }
|
10
|
+
|
9
11
|
before :each do
|
10
|
-
@cli = Hackpad::Cli::Runner.new
|
11
12
|
Hackpad::Cli::Client.stub(:new, {}).and_return(Object)
|
12
13
|
end
|
13
14
|
|
14
15
|
it "calls the search method in client class" do
|
15
16
|
Object.stub(:search)
|
16
|
-
|
17
|
-
|
17
|
+
cli.shell.mute do
|
18
|
+
cli.search "xxx"
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
it "calls the list method in client class" do
|
22
23
|
Object.stub(:list)
|
23
|
-
|
24
|
-
|
24
|
+
cli.shell.mute do
|
25
|
+
cli.list
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
it "calls the list method in client class" do
|
29
30
|
Object.stub(:list)
|
30
|
-
|
31
|
-
|
31
|
+
cli.shell.mute do
|
32
|
+
cli.list
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
36
|
it "calls the info method in client class" do
|
36
37
|
Object.stub(:info)
|
37
|
-
|
38
|
-
|
38
|
+
cli.shell.mute do
|
39
|
+
cli.info 'pad'
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
43
|
it "calls the show method in client class" do
|
43
44
|
Object.stub(:show)
|
44
|
-
|
45
|
-
|
45
|
+
cli.shell.mute do
|
46
|
+
cli.show 'pad', 'md'
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -5,23 +5,49 @@ require "hackpad/cli/store"
|
|
5
5
|
|
6
6
|
describe Hackpad::Cli::Store do
|
7
7
|
|
8
|
+
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
9
|
+
let(:options) { { configdir: configdir, workspace: 'default' } }
|
10
|
+
|
8
11
|
before :each do
|
9
|
-
options
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
subject.prepare options
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".read_list" do
|
16
|
+
before { File.stub(:read).and_return("gy23ui first one\ngy3u4 second one\n23489g [some time] third") }
|
17
|
+
let(:list) { subject.read_list }
|
18
|
+
it { expect(list).to be_an Array }
|
19
|
+
it { expect(list[0]).to be_an OpenStruct }
|
20
|
+
it { expect(list[0].id).to eq "gy23ui" }
|
21
|
+
it { expect(list[0].title).to eq "first one" }
|
22
|
+
it { expect(list[2].id).to eq "23489g" }
|
23
|
+
it { expect(list[2].title).to eq "third" }
|
24
|
+
it { expect(list[2].cached_at).to eq "some time" }
|
14
25
|
end
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
describe ".exists?" do
|
28
|
+
|
29
|
+
context "when refresh option is set," do
|
30
|
+
let(:options) { { configdir: configdir, workspace: 'default', refresh: true } }
|
31
|
+
before {
|
32
|
+
subject.prepare options
|
33
|
+
FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx')
|
34
|
+
}
|
35
|
+
after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
36
|
+
it { expect(subject.exists? 'txt', 'xxx').to be false }
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when refresh option is not set," do
|
40
|
+
context "when config file don't exist," do
|
41
|
+
it { expect(subject.exists? 'txt', 'xxx').to be false }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when configfile exists," do
|
45
|
+
before { FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
46
|
+
after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
47
|
+
it { expect(subject.exists? 'txt', 'xxx').to be true }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
25
51
|
end
|
26
52
|
|
27
53
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hackpad-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: codeclimate-test-reporter
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
description: A Command Line Interface for consuming the Hackpad REST API.
|
140
154
|
email:
|
141
155
|
- mose@mose.com
|
@@ -167,6 +181,7 @@ files:
|
|
167
181
|
- lib/hackpad/cli/store.rb
|
168
182
|
- lib/hackpad/cli/version.rb
|
169
183
|
- spec/lib/hackpad/cli/client_spec.rb
|
184
|
+
- spec/lib/hackpad/cli/config_spec.rb
|
170
185
|
- spec/lib/hackpad/cli/pad_spec.rb
|
171
186
|
- spec/lib/hackpad/cli/runner_spec.rb
|
172
187
|
- spec/lib/hackpad/cli/store_spec.rb
|
@@ -197,6 +212,7 @@ specification_version: 4
|
|
197
212
|
summary: CLI for hackpad browsing and editing.
|
198
213
|
test_files:
|
199
214
|
- spec/lib/hackpad/cli/client_spec.rb
|
215
|
+
- spec/lib/hackpad/cli/config_spec.rb
|
200
216
|
- spec/lib/hackpad/cli/pad_spec.rb
|
201
217
|
- spec/lib/hackpad/cli/runner_spec.rb
|
202
218
|
- spec/lib/hackpad/cli/store_spec.rb
|