hackpad-cli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -0
- data/README.md +4 -2
- data/hackpad-cli.gemspec +3 -3
- data/lib/hackpad/cli/api.rb +13 -14
- data/lib/hackpad/cli/client.rb +15 -10
- data/lib/hackpad/cli/config.rb +16 -51
- data/lib/hackpad/cli/runner.rb +7 -3
- data/lib/hackpad/cli/store.rb +3 -3
- data/lib/hackpad/cli/workspace.rb +37 -0
- data/lib/reverse_markdown/converters/head.rb +12 -0
- data/spec/files/test/sample.html +0 -0
- data/spec/files/test/sample.md +0 -0
- data/spec/lib/hackpad/cli/api_spec.rb +2 -2
- data/spec/lib/hackpad/cli/client_spec.rb +7 -10
- data/spec/lib/hackpad/cli/config_spec.rb +8 -15
- data/spec/lib/hackpad/cli/pad_spec.rb +2 -2
- data/spec/lib/hackpad/cli/runner_spec.rb +9 -1
- data/spec/lib/hackpad/cli/store_spec.rb +14 -22
- data/spec/lib/hackpad/cli/workspace_spec.rb +55 -0
- metadata +27 -6
- data/lib/hackpad/cli/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8774385bd325fd9f7f74ec8e474ac4fdd046792a
|
4
|
+
data.tar.gz: f920f8ef31cb29a8c13a6dc526924f3e511a1008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea50d0b7e670b9f84d2db83602e14e5774b6aa0001fd076b56cd8410d4e41d10ff4a2c5ebaffb2aae26023cdcca6de55edf3dfe9860100331291736b1a2f9f57
|
7
|
+
data.tar.gz: 76318cb2d86cc38a35fa2da5b896b3b679fb8e61517709bd49fe6f761fca6106ac8c9c53bd4603df105aa98a09e5fa639e062a738a337d5ea9854cd31b698ebb
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.1
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,7 @@ Usage
|
|
42
42
|
|
43
43
|
```
|
44
44
|
Commands:
|
45
|
+
hpcli add # Add a new workspace.
|
45
46
|
hpcli default # change the default workspace.
|
46
47
|
hpcli getnew # Downloads the new pads the are not cached yet (options: -u to show urls).
|
47
48
|
hpcli help [COMMAND] # Describe available commands or one specific command
|
@@ -54,7 +55,7 @@ Commands:
|
|
54
55
|
hpcli workspaces # Lists configurated hackpad workspaces.
|
55
56
|
|
56
57
|
Options:
|
57
|
-
-c, [--
|
58
|
+
-c, [--basedir=BASEDIR] # Path to the hackpad-cli directory to use.
|
58
59
|
# Default: /home/mose/.hackpad-cli/
|
59
60
|
-w, [--workspace=WORKSPACE] # Name of the workspace to use.
|
60
61
|
# Default: default
|
@@ -76,7 +77,8 @@ Check the [Changelog](CHANGELOG.md) for past evolutions.
|
|
76
77
|
- <s>display cached date in output</s>
|
77
78
|
- <s>write proper tests</s>
|
78
79
|
- for v0.2.0
|
79
|
-
- clean the markdown generated by reverse_markdown
|
80
|
+
- <s>clean the markdown generated by reverse_markdown</s>
|
81
|
+
- <s>flood hackpad support to get some improvements done</s>
|
80
82
|
- add a command for searching on local cache, in titles only or in body
|
81
83
|
- elaborate a better search syntax so we can have and/or and strings
|
82
84
|
- add commands for creating a new pad, linked to $EDITOR
|
data/hackpad-cli.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'hackpad/cli/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = 'hackpad-cli'
|
8
|
-
spec.version =
|
7
|
+
spec.version = File.read(File.expand_path('../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
|
9
8
|
spec.authors = ['mose']
|
10
9
|
spec.email = ['mose@mose.com']
|
11
10
|
spec.summary = %q(CLI for hackpad browsing and editing.)
|
@@ -19,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
19
18
|
spec.require_paths = ['lib']
|
20
19
|
|
21
20
|
spec.add_dependency 'thor'
|
22
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'configstruct', '~> 0.0.3'
|
22
|
+
spec.add_dependency 'cliprompt', '~> 0.1.0'
|
23
23
|
spec.add_dependency 'paint'
|
24
24
|
spec.add_dependency 'oauth'
|
25
25
|
spec.add_dependency 'reverse_markdown'
|
data/lib/hackpad/cli/api.rb
CHANGED
@@ -3,6 +3,8 @@ require 'net/http'
|
|
3
3
|
require 'json'
|
4
4
|
require 'reverse_markdown'
|
5
5
|
|
6
|
+
require_relative '../../reverse_markdown/converters/head'
|
7
|
+
|
6
8
|
module Hackpad
|
7
9
|
module Cli
|
8
10
|
|
@@ -12,13 +14,9 @@ module Hackpad
|
|
12
14
|
module Api
|
13
15
|
module_function
|
14
16
|
|
15
|
-
def prepare(
|
16
|
-
|
17
|
-
|
18
|
-
config.secret,
|
19
|
-
site: config.site
|
20
|
-
)
|
21
|
-
@token = OAuth::AccessToken.new consumer
|
17
|
+
def prepare(workspace)
|
18
|
+
@hackpad ||= OAuth::Consumer.new(workspace.client_id, workspace.secret, site: workspace.site)
|
19
|
+
@version = File.read(File.expand_path('../../../../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
|
22
20
|
end
|
23
21
|
|
24
22
|
def search(term, start = 0)
|
@@ -35,12 +33,12 @@ module Hackpad
|
|
35
33
|
|
36
34
|
def read(id, ext)
|
37
35
|
realext = (ext == 'md') ? 'html' : ext
|
38
|
-
get "/api/1.0/pad/#{id}/content.#{realext}", false, (ext == 'md')
|
36
|
+
get "/api/1.0/pad/#{id}/content/latest.#{realext}", false, (ext == 'md')
|
39
37
|
end
|
40
38
|
|
41
39
|
def get(url, json = true, to_md = false)
|
42
|
-
res = @
|
43
|
-
if res.is_a? Net::
|
40
|
+
res = @hackpad.request :get, url
|
41
|
+
if res.is_a? Net::HTTPOK
|
44
42
|
if json
|
45
43
|
JSON.parse(res.body)
|
46
44
|
else
|
@@ -57,10 +55,11 @@ module Hackpad
|
|
57
55
|
|
58
56
|
def cleanup_md(text)
|
59
57
|
back = ReverseMarkdown.convert(text, github_flavored: true).strip
|
60
|
-
back.
|
61
|
-
back.gsub!(
|
62
|
-
back.gsub!(
|
63
|
-
back.gsub(/\n\n
|
58
|
+
back.gsub!(/\n-\s*\n/m, "\n") # empty list items
|
59
|
+
back.gsub!(/\n\\\*\s*\n/m, "\n") # images are shown as \*
|
60
|
+
back.gsub!(/-([^\n]+)\n\n -/m, "-\\1\n -") # avoid extra blank lines in lists
|
61
|
+
back.gsub!(/\n( )*-([^\n]+)\n?\n( )*-([^\n]+)\n?\n/m, "\n\\1-\\2\n\\3-\\4\n") # another more generalist for lists
|
62
|
+
back.gsub(/\n\n?\*\*([^\*]+)\*\*\n\n?/, "\n\n### \\1\n\n") # transform isolated titles from bold to h3
|
64
63
|
end
|
65
64
|
|
66
65
|
end
|
data/lib/hackpad/cli/client.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'paint'
|
2
2
|
|
3
3
|
require_relative 'config'
|
4
|
+
require_relative 'workspace'
|
4
5
|
require_relative 'api'
|
5
6
|
require_relative 'store'
|
6
7
|
require_relative 'pad'
|
@@ -15,13 +16,17 @@ module Hackpad
|
|
15
16
|
def initialize(options, input = STDIN, output = STDOUT)
|
16
17
|
@output = output
|
17
18
|
@input = input
|
18
|
-
@
|
19
|
-
|
20
|
-
Store.prepare @config
|
21
|
-
Api.prepare @config
|
22
|
-
if @options[:plain] == true || @config.use_colors == false
|
19
|
+
@config = Config.new options, @input, @output
|
20
|
+
if options[:plain] == true || @config.use_colors == false
|
23
21
|
Paint.mode = 0
|
24
22
|
end
|
23
|
+
@workspace = Workspace.new({ basedir: File.join(@config.basedir, @config.workspace), name: @config.workspace }, @input, @output)
|
24
|
+
Store.prepare @config, @workspace
|
25
|
+
Api.prepare @workspace
|
26
|
+
end
|
27
|
+
|
28
|
+
def add
|
29
|
+
@workspace.clone.create
|
25
30
|
end
|
26
31
|
|
27
32
|
def workspaces
|
@@ -38,7 +43,7 @@ module Hackpad
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def stats
|
41
|
-
table 'Site', Paint[@
|
46
|
+
table 'Site', Paint[@workspace.site, :blue]
|
42
47
|
table 'Cached Pads', Store.count_pads
|
43
48
|
table 'Last Refresh', Store.last_refresh || 'not refreshed yet'
|
44
49
|
end
|
@@ -52,7 +57,7 @@ module Hackpad
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def list
|
55
|
-
@output.puts Padlist.get_list(@
|
60
|
+
@output.puts Padlist.get_list(@config.refresh).map { |pad|
|
56
61
|
padline pad
|
57
62
|
}
|
58
63
|
end
|
@@ -74,7 +79,7 @@ module Hackpad
|
|
74
79
|
pad.load 'txt'
|
75
80
|
table 'Id', Paint[id, :bold]
|
76
81
|
table 'Title', Paint[pad.title, :yellow]
|
77
|
-
table 'URI', "#{@
|
82
|
+
table 'URI', "#{@workspace.site}/#{id}"
|
78
83
|
table 'Chars', "#{pad.chars}"
|
79
84
|
table 'Lines', "#{pad.lines}"
|
80
85
|
table 'Guest Policy', "#{pad.guest_policy}"
|
@@ -91,7 +96,7 @@ module Hackpad
|
|
91
96
|
private
|
92
97
|
|
93
98
|
def padline(pad)
|
94
|
-
"#{(@
|
99
|
+
"#{(@workspace.site + '/') if @config.urls}#{pad.id} - #{pad.title}"
|
95
100
|
end
|
96
101
|
|
97
102
|
def unescape(s)
|
@@ -107,7 +112,7 @@ module Hackpad
|
|
107
112
|
end
|
108
113
|
|
109
114
|
def id_or_url(id)
|
110
|
-
"#{(@
|
115
|
+
"#{(@workspace.site + '/') if @config.urls}#{Paint[id, :bold]}"
|
111
116
|
end
|
112
117
|
|
113
118
|
end
|
data/lib/hackpad/cli/config.rb
CHANGED
@@ -1,65 +1,37 @@
|
|
1
|
-
require 'ostruct'
|
2
1
|
require 'cliprompt'
|
2
|
+
require 'configstruct'
|
3
3
|
|
4
4
|
module Hackpad
|
5
5
|
module Cli
|
6
|
-
class Config <
|
6
|
+
class Config < ConfigStruct
|
7
7
|
|
8
8
|
include Cliprompt
|
9
9
|
|
10
|
-
def
|
11
|
-
super
|
12
|
-
@@input = input
|
13
|
-
@@output = output
|
14
|
-
self.configdir ||= File.join(ENV['HOME'], '.hackpad-cli')
|
10
|
+
def set_defaults
|
11
|
+
super
|
15
12
|
self.refresh ||= false
|
16
13
|
self.urls ||= false
|
17
|
-
self.output = output
|
18
|
-
setio input, output
|
19
|
-
patch_1
|
20
|
-
addvalues 'config'
|
21
14
|
self.workspace ||= 'default'
|
22
|
-
|
23
|
-
|
15
|
+
setio @input, @output
|
16
|
+
patch_1
|
24
17
|
end
|
25
18
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
new_ostruct_member(k)
|
33
|
-
send("#{k}=", v)
|
34
|
-
end
|
19
|
+
def setup
|
20
|
+
values = {}
|
21
|
+
output.puts Paint['Create a new hackpad-cli configuration:', :blue]
|
22
|
+
values['use_colors'] = guess 'HPCLI_COLORS', 'Do you want a colored output?', 'Yn'
|
23
|
+
values['workspace'] = guess 'HPCLI_WORKSPACE', 'What is the name of the default workspace?', 'default'
|
24
|
+
write values
|
35
25
|
end
|
36
26
|
|
37
27
|
def workspaces
|
38
|
-
w = Dir.glob(File.join(
|
28
|
+
w = Dir.glob(File.join(self.basedir, '*', 'config.yml')).reduce([]) do |a, path|
|
39
29
|
a << OpenStruct.new(name: File.basename(File.dirname(path)), site: YAML.load_file(path)['site'])
|
40
30
|
a
|
41
31
|
end
|
42
32
|
w.sort_by { |s| s.name }
|
43
33
|
end
|
44
34
|
|
45
|
-
def setup_config(file)
|
46
|
-
values = {}
|
47
|
-
output.puts Paint['Create a new hackpad-cli configuration:', :blue]
|
48
|
-
values['use_colors'] = guess 'HPCLI_COLORS', 'Do you want a colored output?', 'Yn'
|
49
|
-
values['workspace'] = guess 'HPCLI_WORKSPACE', 'What is the name of the default workspace?', 'default'
|
50
|
-
write(file, values)
|
51
|
-
end
|
52
|
-
|
53
|
-
def setup_workspace(file)
|
54
|
-
values = {}
|
55
|
-
output.puts Paint['Workspace configuration.', :blue]
|
56
|
-
output.puts Paint['Gather your information from https://<workspace>.hackpad.com/ep/account/settings/', :bold]
|
57
|
-
values['client_id'] = guess 'HPCLI_CLIENTID', 'What is your Client ID?'
|
58
|
-
values['secret'] = guess 'HPCLI_SECRET', 'What is your Secret Key?'
|
59
|
-
values['site'] = guess('HPCLI_URL', 'What is the URI of your workspace? (ex. https://xxx.hackapd.com)').gsub(/\/$/, '')
|
60
|
-
write(file, values)
|
61
|
-
end
|
62
|
-
|
63
35
|
def change_default
|
64
36
|
values = {}
|
65
37
|
values['use_colors'] = use_colors
|
@@ -67,19 +39,12 @@ module Hackpad
|
|
67
39
|
choices: workspaces.map(&:name),
|
68
40
|
default: workspace,
|
69
41
|
aslist: true
|
70
|
-
|
71
|
-
write(file, values)
|
42
|
+
write values
|
72
43
|
end
|
73
44
|
|
74
45
|
def patch_1
|
75
|
-
if File.exist? File.join(
|
76
|
-
FileUtils.mv File.join(
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def write(file, values)
|
81
|
-
File.open(file, 'w') do |f|
|
82
|
-
f.write YAML.dump(values)
|
46
|
+
if File.exist? File.join(basedir, "#{workspace}.yml")
|
47
|
+
FileUtils.mv File.join(basedir, "#{workspace}.yml"), File.join(basedir, workspace, 'config.yml')
|
83
48
|
end
|
84
49
|
end
|
85
50
|
|
data/lib/hackpad/cli/runner.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'yaml'
|
3
3
|
require_relative 'client'
|
4
|
-
require_relative 'version'
|
5
4
|
|
6
5
|
module Hackpad
|
7
6
|
module Cli
|
@@ -25,7 +24,7 @@ module Hackpad
|
|
25
24
|
}
|
26
25
|
]
|
27
26
|
|
28
|
-
class_option :
|
27
|
+
class_option :basedir,
|
29
28
|
aliases: '-c',
|
30
29
|
default: File.join(ENV['HOME'], '.hackpad-cli/'),
|
31
30
|
desc: 'Path to the hackpad-cli directory to use.'
|
@@ -48,6 +47,11 @@ module Hackpad
|
|
48
47
|
Hackpad::Cli::Client.new(options).workspaces
|
49
48
|
end
|
50
49
|
|
50
|
+
desc 'add', 'Add a new workspace.'
|
51
|
+
def add
|
52
|
+
Hackpad::Cli::Client.new(options).add
|
53
|
+
end
|
54
|
+
|
51
55
|
desc 'default', 'change the default workspace.'
|
52
56
|
def default
|
53
57
|
Hackpad::Cli::Client.new(options).default
|
@@ -90,7 +94,7 @@ module Hackpad
|
|
90
94
|
|
91
95
|
desc 'version', 'Displays the hackpad-cli version.'
|
92
96
|
def version
|
93
|
-
puts
|
97
|
+
puts File.read(File.expand_path('../../../../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
|
94
98
|
end
|
95
99
|
|
96
100
|
end
|
data/lib/hackpad/cli/store.rb
CHANGED
@@ -9,10 +9,10 @@ module Hackpad
|
|
9
9
|
module Store
|
10
10
|
module_function
|
11
11
|
|
12
|
-
def prepare(config)
|
12
|
+
def prepare(config, workspace)
|
13
13
|
@refresh = config.refresh
|
14
|
-
@configdir = config.
|
15
|
-
@pads_dir = File.join(
|
14
|
+
@configdir = config.basedir
|
15
|
+
@pads_dir = File.join(workspace.basedir, 'pads')
|
16
16
|
@list_cache = File.join(@pads_dir, 'padlist')
|
17
17
|
prepare_dirs @pads_dir
|
18
18
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'cliprompt'
|
2
|
+
require 'configstruct'
|
3
|
+
|
4
|
+
module Hackpad
|
5
|
+
module Cli
|
6
|
+
class Workspace < ConfigStruct
|
7
|
+
|
8
|
+
include Cliprompt
|
9
|
+
|
10
|
+
def set_defaults
|
11
|
+
super
|
12
|
+
self.name ||= 'default'
|
13
|
+
self.url ||= 'http://hackpad.com'
|
14
|
+
setio @input, @output
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
values = {}
|
19
|
+
puts Paint['Workspace configuration.', :blue]
|
20
|
+
puts Paint['Gather your information from https://<workspace>.hackpad.com/ep/account/settings/', :bold]
|
21
|
+
values['client_id'] = guess 'HPCLI_CLIENTID', 'What is your Client ID?'
|
22
|
+
values['secret'] = guess 'HPCLI_SECRET', 'What is your Secret Key?'
|
23
|
+
values['site'] = guess('HPCLI_URL', 'What is the URI of your workspace? (ex. https://xxx.hackpad.com)').gsub(/\/$/, '')
|
24
|
+
write values
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
self.name = ask "What is the name of the new workspace?"
|
29
|
+
self.basedir = File.expand_path("../#{self.name}", self.basedir)
|
30
|
+
self.basefile = File.join(self.basedir, 'config.yml')
|
31
|
+
prepare_dirs
|
32
|
+
setup
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
File without changes
|
@@ -70,7 +70,7 @@ describe Hackpad::Cli::Api do
|
|
70
70
|
.with(headers: {
|
71
71
|
'Accept' => '*/*',
|
72
72
|
'Authorization' => /OAuth oauth_consumer_key="123"/,
|
73
|
-
'User-Agent' => /hackpad-cli v
|
73
|
+
'User-Agent' => /hackpad-cli v/
|
74
74
|
})
|
75
75
|
.to_return(status: 200, body: '{"some": "result"}')
|
76
76
|
expect(Hackpad::Cli::Api.get('/api/1.0/xxx')).to eq('some' => 'result')
|
@@ -82,7 +82,7 @@ describe Hackpad::Cli::Api do
|
|
82
82
|
.with(headers: {
|
83
83
|
'Accept' => '*/*',
|
84
84
|
'Authorization' => /OAuth oauth_consumer_key="123"/,
|
85
|
-
'User-Agent' => /hackpad-cli v
|
85
|
+
'User-Agent' => /hackpad-cli v/
|
86
86
|
})
|
87
87
|
.to_return(status: 404, body: '{"some": "result"}')
|
88
88
|
expect { Hackpad::Cli::Api.get('/api/1.0/xxx') }
|
@@ -11,7 +11,7 @@ describe Hackpad::Cli::Client do
|
|
11
11
|
let(:workspacefile) { File.join(workspacedir, 'config.yml') }
|
12
12
|
let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } }
|
13
13
|
let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
|
14
|
-
let(:options) { {
|
14
|
+
let(:options) { { basedir: configdir, workspace: 'default' } }
|
15
15
|
let(:format) { "%-20s %s\n" }
|
16
16
|
let(:input) { StringIO.new }
|
17
17
|
let(:output) { StringIO.new }
|
@@ -49,9 +49,8 @@ describe Hackpad::Cli::Client do
|
|
49
49
|
after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
|
50
50
|
|
51
51
|
it do
|
52
|
-
expect(output).to receive(:printf).with(format, '> default', 'http://example.com')
|
53
|
-
expect(output).to receive(:printf).with(format, 'default2', 'http://2.example.com')
|
54
52
|
client.workspaces
|
53
|
+
expect(output.string).to eq "> default http://example.com\ndefault2 http://2.example.com\n"
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -66,8 +65,8 @@ describe Hackpad::Cli::Client do
|
|
66
65
|
after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
|
67
66
|
|
68
67
|
it do
|
69
|
-
expect(output).to receive(:print).with("What workspace do you want to use as default from now on? \n> 0 default\n 1 default2\nChoose a number: [0] ")
|
70
68
|
client.default
|
69
|
+
expect(output.string).to eq "What workspace do you want to use as default from now on? \n> 0 default\n 1 default2\nChoose a number: [0] "
|
71
70
|
expect(YAML.load_file(configfile)['workspace']).to eq 'default2'
|
72
71
|
end
|
73
72
|
end
|
@@ -79,10 +78,8 @@ describe Hackpad::Cli::Client do
|
|
79
78
|
before { Hackpad::Cli::Store.stub(:last_refresh).and_return(timestamp) }
|
80
79
|
let(:client) { Hackpad::Cli::Client.new(options, input, output) }
|
81
80
|
it do
|
82
|
-
expect(output).to receive(:printf).with(format, 'Site', Paint[workspacevars['site'], :blue])
|
83
|
-
expect(output).to receive(:printf).with(format, 'Cached Pads', 12)
|
84
|
-
expect(output).to receive(:printf).with(format, 'Last Refresh', timestamp)
|
85
81
|
client.stats
|
82
|
+
expect(output.string).to eq "Site #{Paint[workspacevars['site'], :blue]}\nCached Pads 12\nLast Refresh #{timestamp}\n"
|
86
83
|
end
|
87
84
|
end
|
88
85
|
|
@@ -111,9 +108,8 @@ describe Hackpad::Cli::Client do
|
|
111
108
|
context 'when options sets urls to true,' do
|
112
109
|
let(:client) { Hackpad::Cli::Client.new(options.merge(urls: true), input, output) }
|
113
110
|
it do
|
114
|
-
expect(output).to receive(:puts).with("#{workspacevars['site']}/#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}")
|
115
|
-
expect(output).to receive(:puts).with(" context #{Paint['x', :cyan, :bold]} context")
|
116
111
|
client.search 'xxx'
|
112
|
+
expect(output.string).to eq "#{workspacevars['site']}/#{Paint['xxxxxx', :bold]} - #{Paint['xtitle', :yellow]}\n context #{Paint['x', :cyan, :bold]} context\n"
|
117
113
|
end
|
118
114
|
end
|
119
115
|
end
|
@@ -197,7 +193,7 @@ describe Hackpad::Cli::Client do
|
|
197
193
|
before { pad.stub(:lines).and_return(2) }
|
198
194
|
before { pad.stub(:guest_policy).and_return('open') }
|
199
195
|
before { pad.stub(:moderated).and_return('false') }
|
200
|
-
before { pad.stub(:cached_at).and_return }
|
196
|
+
before { pad.stub(:cached_at).and_return('unknown') }
|
201
197
|
it do
|
202
198
|
expect(output).to receive(:printf).with(format, 'Id', Paint["123", :bold])
|
203
199
|
expect(output).to receive(:printf).with(format, 'Title', Paint['title1', :yellow])
|
@@ -208,6 +204,7 @@ describe Hackpad::Cli::Client do
|
|
208
204
|
expect(output).to receive(:printf).with(format, 'Moderated', 'false')
|
209
205
|
expect(output).to receive(:printf).with(format, 'Cached', 'unknown')
|
210
206
|
client.info '123'
|
207
|
+
|
211
208
|
end
|
212
209
|
end
|
213
210
|
|
@@ -7,50 +7,43 @@ describe Hackpad::Cli::Config do
|
|
7
7
|
|
8
8
|
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
9
9
|
let(:configfile) { File.join(configdir, 'config.yml') }
|
10
|
-
let(:
|
11
|
-
let(:workspacefile) { File.join(workspacedir, 'config.yml') }
|
12
|
-
let(:options) { { configdir: configdir, workspace: 'default' } }
|
10
|
+
let(:options) { { basedir: configdir, workspace: 'default' } }
|
13
11
|
let(:input) { StringIO.new }
|
14
12
|
let(:output) { StringIO.new }
|
15
13
|
|
16
14
|
before { FileUtils.mkdir_p configdir unless Dir.exist?(configdir) }
|
17
|
-
before { FileUtils.mkdir_p workspacedir unless Dir.exist?(workspacedir) }
|
18
|
-
|
19
15
|
after { FileUtils.rm configfile if File.exist?(configfile) }
|
20
|
-
after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
|
21
16
|
|
22
17
|
describe '.new' do
|
23
18
|
context 'when there is already config files created,' do
|
24
19
|
let(:configvars) { { 'use_colors' => true, 'workspace' => 'default' } }
|
25
|
-
let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
|
26
20
|
before { File.open(configfile, 'w') { |f| f.puts YAML.dump(configvars) } }
|
27
|
-
before { File.open(workspacefile, 'w') { |f| f.puts YAML.dump(workspacevars) } }
|
28
21
|
let(:config) { Hackpad::Cli::Config.new(options) }
|
29
22
|
it {
|
30
|
-
expect(config.
|
31
|
-
expect(config.site).to eq 'http://example.com'
|
23
|
+
expect(config.workspace).to eq 'default'
|
32
24
|
}
|
33
25
|
end
|
34
26
|
context 'when there is no config files created,' do
|
35
|
-
before { input.stub(:gets).and_return('y', 'default'
|
27
|
+
before { input.stub(:gets).and_return('y', 'default') }
|
36
28
|
let(:config) { Hackpad::Cli::Config.new(options, input, output) }
|
37
29
|
it {
|
38
|
-
expect(config.
|
39
|
-
expect(config.site).to eq 'http://example.com'
|
30
|
+
expect(config.workspace).to eq 'default'
|
40
31
|
}
|
41
32
|
end
|
42
33
|
end
|
43
34
|
|
44
35
|
describe '.patch_1' do
|
45
36
|
let(:oldconfigfile) { File.join(configdir, 'default.yml') }
|
37
|
+
let(:workspacefile) { File.join(configdir, 'default', 'config.yml') }
|
46
38
|
let(:oldconfigvars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
|
47
39
|
before { File.open(oldconfigfile, 'w') { |f| f.puts YAML.dump(oldconfigvars) } }
|
48
40
|
before { input.stub(:gets).and_return('y', 'default') }
|
49
41
|
after { FileUtils.rm oldconfigfile if File.exist?(oldconfigfile) }
|
42
|
+
after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
|
50
43
|
it do
|
51
44
|
Hackpad::Cli::Config.new(options, input, output)
|
52
|
-
expect(File.exist? oldconfigfile).to
|
53
|
-
expect(File.exist?
|
45
|
+
expect(File.exist? oldconfigfile).to be false
|
46
|
+
expect(File.exist? workspacefile).to be true
|
54
47
|
end
|
55
48
|
end
|
56
49
|
|
@@ -16,7 +16,7 @@ describe Hackpad::Cli::Pad do
|
|
16
16
|
|
17
17
|
describe '.cached?' do
|
18
18
|
before { Hackpad::Cli::Store.stub(:exist?).and_return true }
|
19
|
-
it { expect(pad.cached?).to
|
19
|
+
it { expect(pad.cached?).to be true }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when the pad has no data,' do
|
@@ -67,7 +67,7 @@ describe Hackpad::Cli::Pad do
|
|
67
67
|
before { pad.load_from_provider Hackpad::Cli::Store, 'txt' }
|
68
68
|
it { expect(pad.content).to eq "This\nis\nInformation!" }
|
69
69
|
it { expect(pad.guest_policy).to eq 'open' }
|
70
|
-
it { expect(pad.moderated).to
|
70
|
+
it { expect(pad.moderated).to be false }
|
71
71
|
it { expect(pad.cached_at).to eq 'some time' }
|
72
72
|
end
|
73
73
|
end
|
@@ -26,6 +26,13 @@ describe Hackpad::Cli::Runner do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'calls the add method in client class' do
|
30
|
+
Object.stub(:add)
|
31
|
+
cli.shell.mute do
|
32
|
+
cli.add
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
29
36
|
it 'calls the workspaces method in client class' do
|
30
37
|
Object.stub(:workspaces)
|
31
38
|
cli.shell.mute do
|
@@ -55,7 +62,8 @@ describe Hackpad::Cli::Runner do
|
|
55
62
|
end
|
56
63
|
|
57
64
|
it 'calls the version method in client class' do
|
58
|
-
|
65
|
+
version = File.read(File.expand_path('../../../../../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
|
66
|
+
STDOUT.stub(:puts).with(version)
|
59
67
|
cli.shell.mute do
|
60
68
|
cli.version
|
61
69
|
end
|
@@ -3,19 +3,18 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'hackpad/cli/store'
|
5
5
|
require 'hackpad/cli/pad'
|
6
|
+
require 'hackpad/cli/config'
|
7
|
+
require 'hackpad/cli/workspace'
|
6
8
|
|
7
9
|
describe Hackpad::Cli::Store do
|
8
10
|
|
9
11
|
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
10
|
-
let(:
|
11
|
-
|
12
|
-
|
13
|
-
workspacedir: File.join(configdir, 'default')
|
14
|
-
)
|
15
|
-
}
|
12
|
+
let(:workspacedir) { File.expand_path('../../../../files/default', __FILE__) }
|
13
|
+
let(:config) { OpenStruct.new(basedir: configdir, refresh: false, workspace: 'default') }
|
14
|
+
let(:workspace) { OpenStruct.new(basedir: workspacedir) }
|
16
15
|
|
17
16
|
before :each do
|
18
|
-
subject.prepare
|
17
|
+
subject.prepare config, workspace
|
19
18
|
end
|
20
19
|
|
21
20
|
describe '.read_list' do
|
@@ -41,7 +40,7 @@ describe Hackpad::Cli::Store do
|
|
41
40
|
)
|
42
41
|
}
|
43
42
|
before do
|
44
|
-
subject.prepare options
|
43
|
+
subject.prepare options, workspace
|
45
44
|
FileUtils.touch File.join(configdir, 'default', 'pads', 'txt', 'xxx')
|
46
45
|
end
|
47
46
|
after { FileUtils.rm File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
@@ -65,11 +64,10 @@ describe Hackpad::Cli::Store do
|
|
65
64
|
describe '.save' do
|
66
65
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
67
66
|
let(:content) { "This is content\n" }
|
68
|
-
before { subject.prepare options }
|
69
67
|
let(:pad) { double Hackpad::Cli::Pad }
|
70
68
|
before { pad.stub(:id).and_return 'xxx' }
|
71
69
|
before { pad.stub(:content).and_return content }
|
72
|
-
after { FileUtils.rm padfile }
|
70
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
73
71
|
it do
|
74
72
|
subject.save pad, 'txt'
|
75
73
|
expect(File.read(padfile)).to eq content
|
@@ -79,8 +77,7 @@ describe Hackpad::Cli::Store do
|
|
79
77
|
describe '.save_options' do
|
80
78
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'meta', 'xxx') }
|
81
79
|
let(:content) { { thing: '123', other: 'option' } }
|
82
|
-
|
83
|
-
after { FileUtils.rm padfile }
|
80
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
84
81
|
it do
|
85
82
|
subject.save_options 'xxx', content
|
86
83
|
expect(File.read(padfile)).to eq "{\n \"thing\": \"123\",\n \"other\": \"option\"\n}\n"
|
@@ -90,8 +87,7 @@ describe Hackpad::Cli::Store do
|
|
90
87
|
describe '.save_list' do
|
91
88
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'padlist') }
|
92
89
|
let(:pads) { [OpenStruct.new(id: '123', cached_at: 'some time', title: 'title1')] }
|
93
|
-
|
94
|
-
after { FileUtils.rm padfile }
|
90
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
95
91
|
it do
|
96
92
|
subject.save_list pads
|
97
93
|
expect(File.read(padfile)).to eq "123 [some time] title1\n"
|
@@ -101,12 +97,11 @@ describe Hackpad::Cli::Store do
|
|
101
97
|
describe '.read' do
|
102
98
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'txt', 'xxx') }
|
103
99
|
let(:content) { "This is content\n" }
|
104
|
-
before { subject.prepare options }
|
105
100
|
let(:pad) { double Hackpad::Cli::Pad }
|
106
101
|
before { pad.stub(:id).and_return 'xxx' }
|
107
102
|
before { pad.stub(:content).and_return content }
|
108
103
|
before { subject.save pad, 'txt' }
|
109
|
-
after { FileUtils.rm padfile }
|
104
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
110
105
|
|
111
106
|
it { expect(subject.read 'xxx', 'txt').to eq content }
|
112
107
|
end
|
@@ -114,18 +109,16 @@ describe Hackpad::Cli::Store do
|
|
114
109
|
describe '.read_option' do
|
115
110
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'meta', 'xxx') }
|
116
111
|
let(:content) { { 'thing' => '123', 'other' => 'option' } }
|
117
|
-
before { subject.prepare options }
|
118
112
|
before { subject.save_options 'xxx', content }
|
119
|
-
after { FileUtils.rm padfile }
|
113
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
120
114
|
it { expect(subject.read_options 'xxx').to eq content }
|
121
115
|
end
|
122
116
|
|
123
117
|
describe '.count_pads' do
|
124
118
|
let(:padfile) { File.join(configdir, 'default', 'pads', 'meta', 'xxx') }
|
125
119
|
let(:content) { { 'thing' => '123', 'other' => 'option' } }
|
126
|
-
before { subject.prepare options }
|
127
120
|
before { subject.save_options 'xxx', content }
|
128
|
-
after { FileUtils.rm padfile }
|
121
|
+
after { FileUtils.rm padfile if File.exist?(padfile) }
|
129
122
|
it { expect(subject.count_pads).to be 1 }
|
130
123
|
end
|
131
124
|
|
@@ -133,12 +126,11 @@ describe Hackpad::Cli::Store do
|
|
133
126
|
let(:timestamp) { Time.new(2012, 10, 31) }
|
134
127
|
let(:padlist) { File.join(configdir, 'default', 'pads', 'padlist') }
|
135
128
|
let(:pads) { [OpenStruct.new(id: '123', cached_at: 'some time', title: 'title1')] }
|
136
|
-
before { subject.prepare options }
|
137
129
|
before do
|
138
130
|
subject.save_list pads
|
139
131
|
FileUtils.touch padlist, mtime: timestamp
|
140
132
|
end
|
141
|
-
after { FileUtils.rm padlist }
|
133
|
+
after { FileUtils.rm padlist if File.exist?(padlist) }
|
142
134
|
it { expect(subject.last_refresh).to eq timestamp }
|
143
135
|
end
|
144
136
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'hackpad/cli/workspace'
|
5
|
+
|
6
|
+
describe Hackpad::Cli::Workspace do
|
7
|
+
|
8
|
+
let(:configdir) { File.expand_path('../../../../files', __FILE__) }
|
9
|
+
let(:workspacedir) { File.join(configdir, 'default') }
|
10
|
+
let(:workspacedir) { File.join(configdir, 'default') }
|
11
|
+
let(:workspacefile) { File.join(workspacedir, 'config.yml') }
|
12
|
+
let(:options) { { basedir: workspacedir, basefile: workspacefile } }
|
13
|
+
let(:input) { StringIO.new }
|
14
|
+
let(:output) { StringIO.new }
|
15
|
+
|
16
|
+
before { FileUtils.mkdir_p configdir unless Dir.exist?(configdir) }
|
17
|
+
before { FileUtils.mkdir_p workspacedir unless Dir.exist?(workspacedir) }
|
18
|
+
|
19
|
+
after { FileUtils.rm workspacefile if File.exist?(workspacefile) }
|
20
|
+
|
21
|
+
describe '.new' do
|
22
|
+
context 'when there is already config files created,' do
|
23
|
+
let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
|
24
|
+
before { File.open(workspacefile, 'w') { |f| f.puts YAML.dump(workspacevars) } }
|
25
|
+
let(:workspace) { Hackpad::Cli::Workspace.new(options) }
|
26
|
+
it {
|
27
|
+
expect(workspace.secret).to eq 'toto'
|
28
|
+
expect(workspace.site).to eq 'http://example.com'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
context 'when there is no config files created,' do
|
32
|
+
before { input.stub(:gets).and_return('123', 'toto', 'http://example.com') }
|
33
|
+
let(:workspace) { Hackpad::Cli::Workspace.new(options, input, output) }
|
34
|
+
it {
|
35
|
+
expect(workspace.secret).to eq 'toto'
|
36
|
+
expect(workspace.site).to eq 'http://example.com'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.create' do
|
42
|
+
let(:workspacevars) { { 'client_id' => '123', 'secret' => 'toto', 'site' => 'http://example.com' } }
|
43
|
+
before { File.open(workspacefile, 'w') { |f| f.puts YAML.dump(workspacevars) } }
|
44
|
+
let!(:workspace) { Hackpad::Cli::Workspace.new(options, input, output) }
|
45
|
+
let(:newone) { 'another' }
|
46
|
+
let(:newworkspacefile) { File.join(configdir, newone, 'config.yml') }
|
47
|
+
before { input.stub(:gets).and_return(newone, '123', 'toto', 'http://example.com') }
|
48
|
+
after { FileUtils.rm newworkspacefile if File.exist?(newworkspacefile) }
|
49
|
+
it {
|
50
|
+
workspace.create
|
51
|
+
expect(File.exist? newworkspacefile).to be true
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
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.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -24,20 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: configstruct
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: cliprompt
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0
|
47
|
+
version: 0.1.0
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0
|
54
|
+
version: 0.1.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: paint
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -193,7 +207,10 @@ files:
|
|
193
207
|
- lib/hackpad/cli/padlist.rb
|
194
208
|
- lib/hackpad/cli/runner.rb
|
195
209
|
- lib/hackpad/cli/store.rb
|
196
|
-
- lib/hackpad/cli/
|
210
|
+
- lib/hackpad/cli/workspace.rb
|
211
|
+
- lib/reverse_markdown/converters/head.rb
|
212
|
+
- spec/files/test/sample.html
|
213
|
+
- spec/files/test/sample.md
|
197
214
|
- spec/lib/hackpad/cli/api_spec.rb
|
198
215
|
- spec/lib/hackpad/cli/client_spec.rb
|
199
216
|
- spec/lib/hackpad/cli/config_spec.rb
|
@@ -201,6 +218,7 @@ files:
|
|
201
218
|
- spec/lib/hackpad/cli/padlist_spec.rb
|
202
219
|
- spec/lib/hackpad/cli/runner_spec.rb
|
203
220
|
- spec/lib/hackpad/cli/store_spec.rb
|
221
|
+
- spec/lib/hackpad/cli/workspace_spec.rb
|
204
222
|
- spec/spec_helper.rb
|
205
223
|
homepage: https://github.com/mose/hackpad-cli
|
206
224
|
licenses:
|
@@ -222,11 +240,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
240
|
version: '0'
|
223
241
|
requirements: []
|
224
242
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
243
|
+
rubygems_version: 2.4.6
|
226
244
|
signing_key:
|
227
245
|
specification_version: 4
|
228
246
|
summary: CLI for hackpad browsing and editing.
|
229
247
|
test_files:
|
248
|
+
- spec/files/test/sample.html
|
249
|
+
- spec/files/test/sample.md
|
230
250
|
- spec/lib/hackpad/cli/api_spec.rb
|
231
251
|
- spec/lib/hackpad/cli/client_spec.rb
|
232
252
|
- spec/lib/hackpad/cli/config_spec.rb
|
@@ -234,4 +254,5 @@ test_files:
|
|
234
254
|
- spec/lib/hackpad/cli/padlist_spec.rb
|
235
255
|
- spec/lib/hackpad/cli/runner_spec.rb
|
236
256
|
- spec/lib/hackpad/cli/store_spec.rb
|
257
|
+
- spec/lib/hackpad/cli/workspace_spec.rb
|
237
258
|
- spec/spec_helper.rb
|