cloudapp-cli 1.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +75 -0
- data/MIT-LICENSE +20 -0
- data/README.md +56 -0
- data/Rakefile +139 -0
- data/bin/cloudapp +179 -0
- data/cloudapp-cli.gemspec +83 -0
- data/lib/cloudapp/cli/config.rb +41 -0
- data/lib/cloudapp/cli.rb +8 -0
- data/spec/cloudapp/cli/config_spec.rb +62 -0
- data/spec/helper.rb +4 -0
- metadata +172 -0
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cloudapp-cli (1.0.0.beta.1)
|
5
|
+
cloudapp (~> 2.0.0.beta.1)
|
6
|
+
ffi-ncurses
|
7
|
+
highline
|
8
|
+
ruby-termios
|
9
|
+
|
10
|
+
PATH
|
11
|
+
remote: ~/Code/cloudapp
|
12
|
+
specs:
|
13
|
+
cloudapp (2.0.0.beta.1)
|
14
|
+
leadlight (= 0.0.5)
|
15
|
+
typhoeus (~> 0.3.3)
|
16
|
+
|
17
|
+
GEM
|
18
|
+
remote: http://rubygems.org/
|
19
|
+
specs:
|
20
|
+
addressable (2.3.2)
|
21
|
+
diff-lcs (1.1.3)
|
22
|
+
fail-fast (1.0.0)
|
23
|
+
faraday (0.8.4)
|
24
|
+
multipart-post (~> 1.1)
|
25
|
+
fattr (2.2.1)
|
26
|
+
ffi (1.1.5)
|
27
|
+
ffi-locale (1.0.1)
|
28
|
+
ffi (>= 1.0.9)
|
29
|
+
ffi-ncurses (0.4.0)
|
30
|
+
ffi (>= 1.0.9)
|
31
|
+
ffi-locale (>= 1.0.0)
|
32
|
+
highline (1.6.13)
|
33
|
+
hookr (1.1.1)
|
34
|
+
fail-fast (= 1.0.0)
|
35
|
+
hpricot (0.8.6)
|
36
|
+
leadlight (0.0.5)
|
37
|
+
addressable
|
38
|
+
faraday
|
39
|
+
fattr
|
40
|
+
hookr
|
41
|
+
link_header
|
42
|
+
mime-types
|
43
|
+
multi_json (~> 1.0.4)
|
44
|
+
link_header (0.0.5)
|
45
|
+
mime-types (1.19)
|
46
|
+
multi_json (1.0.4)
|
47
|
+
multipart-post (1.1.5)
|
48
|
+
mustache (0.99.4)
|
49
|
+
rake (0.9.2.2)
|
50
|
+
rdiscount (1.6.8)
|
51
|
+
ronn (0.7.3)
|
52
|
+
hpricot (>= 0.8.2)
|
53
|
+
mustache (>= 0.7.0)
|
54
|
+
rdiscount (>= 1.5.8)
|
55
|
+
rspec (2.11.0)
|
56
|
+
rspec-core (~> 2.11.0)
|
57
|
+
rspec-expectations (~> 2.11.0)
|
58
|
+
rspec-mocks (~> 2.11.0)
|
59
|
+
rspec-core (2.11.1)
|
60
|
+
rspec-expectations (2.11.2)
|
61
|
+
diff-lcs (~> 1.1.3)
|
62
|
+
rspec-mocks (2.11.2)
|
63
|
+
ruby-termios (0.9.6)
|
64
|
+
typhoeus (0.3.3)
|
65
|
+
mime-types
|
66
|
+
|
67
|
+
PLATFORMS
|
68
|
+
ruby
|
69
|
+
|
70
|
+
DEPENDENCIES
|
71
|
+
cloudapp!
|
72
|
+
cloudapp-cli!
|
73
|
+
rake
|
74
|
+
ronn
|
75
|
+
rspec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Linebreak S.L.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# CloudApp CLI
|
2
|
+
|
3
|
+
Experience all the pleasures of sharing with [CloudApp][] from your terminal
|
4
|
+
using a gorgeous and cutting-edge ncurses text user interface.
|
5
|
+
|
6
|
+
[cloudapp]: http://getcloudapp.com
|
7
|
+
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
`cloudapp-cli` requires Ruby 1.9.2 or greater.
|
12
|
+
|
13
|
+
|
14
|
+
## Getting Started
|
15
|
+
|
16
|
+
``` bash
|
17
|
+
gem install cloudapp
|
18
|
+
cloudapp
|
19
|
+
```
|
20
|
+
|
21
|
+
## Wish List
|
22
|
+
|
23
|
+
Along with the ncurses interface, a few simple commands to allow scripting and
|
24
|
+
input from other Unix programs would be ideal.
|
25
|
+
|
26
|
+
### Phase: One
|
27
|
+
|
28
|
+
- Bookmark a link: `cloudapp bookmark http://getcloudapp.com`
|
29
|
+
- Bookmark several links: `cloudapp bookmark http://douglasadams.com http://zombo.com`
|
30
|
+
- Share a file: `cloudapp upload screenshot.png`
|
31
|
+
- Share several files: `cloudapp upload *.png`
|
32
|
+
|
33
|
+
### Phase: Two
|
34
|
+
|
35
|
+
- Handle bookmarks from STDIN: `pbpaste | cloudapp bookmark`
|
36
|
+
- Handle files from STDIN: `find *.png | cloudapp upload`
|
37
|
+
- Download a drop: `cloudapp download http://cl.ly/abc123`
|
38
|
+
|
39
|
+
### Phase: Unstoppable
|
40
|
+
|
41
|
+
- Archive and share several files: `cloudapp upload --archive *.png`
|
42
|
+
- Encrypt and share a file: `cloudapp upload --encrypt launch_codes.txt`
|
43
|
+
- Download and decrypt and encrypted drop: `cloudapp download --key=def456 http://cl.ly/abc123`
|
44
|
+
|
45
|
+
### Phase: World Domination
|
46
|
+
|
47
|
+
While we're dreaming, what could you do if `cloudapp` had a database of all your
|
48
|
+
drops? Bonus points for a light weight daemon that kept everything in sync at
|
49
|
+
all times.
|
50
|
+
|
51
|
+
- Find all your screen shots: `cloudapp list /^screen ?shot.*\.png$/`
|
52
|
+
- Trash all your stale drops: `cloudapp delete --last-viewed="> 1 month ago"`
|
53
|
+
- See your drop views in real time: `cloudapp --tail`
|
54
|
+
|
55
|
+
There's bound to be a better way to express some of these commands, but you get
|
56
|
+
the picture.
|
data/Rakefile
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def primary_file
|
16
|
+
name.tr('-', '/')
|
17
|
+
end
|
18
|
+
|
19
|
+
def version
|
20
|
+
line = File.read("lib/#{primary_file}.rb")[/^\s*VERSION\s*=\s*.*/]
|
21
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
22
|
+
end
|
23
|
+
|
24
|
+
def date
|
25
|
+
Date.today.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def rubyforge_project
|
29
|
+
name
|
30
|
+
end
|
31
|
+
|
32
|
+
def gemspec_file
|
33
|
+
"#{name}.gemspec"
|
34
|
+
end
|
35
|
+
|
36
|
+
def gem_file
|
37
|
+
"#{name}-#{version}.gem"
|
38
|
+
end
|
39
|
+
|
40
|
+
def replace_header(head, header_name)
|
41
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
42
|
+
end
|
43
|
+
|
44
|
+
#############################################################################
|
45
|
+
#
|
46
|
+
# Standard tasks
|
47
|
+
#
|
48
|
+
#############################################################################
|
49
|
+
|
50
|
+
require 'rspec'
|
51
|
+
require 'rspec/core/rake_task'
|
52
|
+
|
53
|
+
desc "Run all specs"
|
54
|
+
task RSpec::Core::RakeTask.new('spec')
|
55
|
+
|
56
|
+
task :default => "spec"
|
57
|
+
|
58
|
+
#############################################################################
|
59
|
+
#
|
60
|
+
# Custom tasks (add your own tasks here)
|
61
|
+
#
|
62
|
+
#############################################################################
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
#############################################################################
|
67
|
+
#
|
68
|
+
# Packaging tasks
|
69
|
+
#
|
70
|
+
#############################################################################
|
71
|
+
|
72
|
+
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
73
|
+
task :release => :build do
|
74
|
+
unless `git branch` =~ /^\* master$/
|
75
|
+
puts "You must be on the master branch to release!"
|
76
|
+
exit!
|
77
|
+
end
|
78
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
79
|
+
sh "git tag v#{version}"
|
80
|
+
sh "git push origin master"
|
81
|
+
sh "git push origin v#{version}"
|
82
|
+
sh "gem push pkg/#{gem_file}"
|
83
|
+
end
|
84
|
+
|
85
|
+
desc "Build #{gem_file} into the pkg directory"
|
86
|
+
task :build => [:gemspec, :update_bundle] do
|
87
|
+
sh "mkdir -p pkg"
|
88
|
+
sh "gem build #{gemspec_file}"
|
89
|
+
sh "mv #{gem_file} pkg"
|
90
|
+
end
|
91
|
+
|
92
|
+
desc "Generate #{gemspec_file}"
|
93
|
+
task :gemspec => :validate do
|
94
|
+
# read spec file and split out manifest section
|
95
|
+
spec = File.read(gemspec_file)
|
96
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
97
|
+
|
98
|
+
# replace name version and date
|
99
|
+
replace_header(head, :name)
|
100
|
+
replace_header(head, :version)
|
101
|
+
replace_header(head, :date)
|
102
|
+
#comment this out if your rubyforge_project has a different name
|
103
|
+
replace_header(head, :rubyforge_project)
|
104
|
+
|
105
|
+
# determine file list from git ls-files
|
106
|
+
files = `git ls-files`.
|
107
|
+
split("\n").
|
108
|
+
sort.
|
109
|
+
reject { |file| file =~ /^\./ }.
|
110
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
111
|
+
map { |file| " #{file}" }.
|
112
|
+
join("\n")
|
113
|
+
|
114
|
+
# piece file back together and write
|
115
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
116
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
117
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
118
|
+
puts "Updated #{gemspec_file}"
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "Update #{name} in bundle"
|
122
|
+
task :update_bundle => :validate do
|
123
|
+
`bundle update #{name}`
|
124
|
+
puts "Bundled #{name} version #{version}"
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Validate #{gemspec_file}"
|
128
|
+
task :validate do
|
129
|
+
libfiles = Dir['lib/*'] + Dir['lib/cloudapp/*'] -
|
130
|
+
['lib/cloudapp', "lib/#{primary_file}", "lib/#{primary_file}.rb"]
|
131
|
+
unless libfiles.empty?
|
132
|
+
puts "Directory `lib` should only contain a `#{primary_file}.rb` file and `#{primary_file}` dir."
|
133
|
+
exit!
|
134
|
+
end
|
135
|
+
unless Dir['VERSION*'].empty?
|
136
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
137
|
+
exit!
|
138
|
+
end
|
139
|
+
end
|
data/bin/cloudapp
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'cloudapp'
|
4
|
+
require 'cloudapp/cli'
|
5
|
+
require 'highline'
|
6
|
+
require 'ffi-ncurses'
|
7
|
+
|
8
|
+
include FFI::NCurses
|
9
|
+
|
10
|
+
def config
|
11
|
+
CloudApp::CLI::Config.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def account
|
15
|
+
require_credentials
|
16
|
+
CloudApp::Account.using_token config.token
|
17
|
+
end
|
18
|
+
|
19
|
+
def require_credentials
|
20
|
+
return unless config.token.nil?
|
21
|
+
|
22
|
+
$stdout.puts 'Sign into your CloudApp account.'
|
23
|
+
|
24
|
+
email = HighLine.new.ask('Email: ')
|
25
|
+
password = HighLine.new.ask('Password: ') {|q| q.echo = false }
|
26
|
+
config.token = CloudApp::Token.for_account email, password
|
27
|
+
end
|
28
|
+
|
29
|
+
def log(*args)
|
30
|
+
File.open('log/curses.txt', 'ab+') do |file|
|
31
|
+
file.puts args.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def copy(link)
|
37
|
+
IO.popen('pbcopy', 'w') {|f| f << link }
|
38
|
+
end
|
39
|
+
|
40
|
+
def draw_drops_window(drops)
|
41
|
+
# 1 column wider than necessary to prevent wrapping also accounting for
|
42
|
+
# selection indicator.
|
43
|
+
width = drops.map {|drop| drop.name.size }.max + 3
|
44
|
+
height = drops.size * 3
|
45
|
+
|
46
|
+
wrap = newwin height + 2, width + 2, 0, 0
|
47
|
+
box wrap, 0, 0
|
48
|
+
wrefresh wrap
|
49
|
+
|
50
|
+
win = newwin height, width, 1, 1
|
51
|
+
|
52
|
+
drops.each do |drop|
|
53
|
+
drop_lines(drop).each do |line|
|
54
|
+
waddstr win, ' '
|
55
|
+
waddstr win, line
|
56
|
+
waddstr win, "\n"
|
57
|
+
end
|
58
|
+
waddstr win, "\n"
|
59
|
+
end
|
60
|
+
wrefresh win
|
61
|
+
|
62
|
+
[ win, wrap ]
|
63
|
+
end
|
64
|
+
|
65
|
+
def drop_lines(drop)
|
66
|
+
details = " #{ pretty_date(drop.created) } (#{ drop.views })"
|
67
|
+
[ drop.name, details ]
|
68
|
+
end
|
69
|
+
|
70
|
+
def select_drop(win, selected_drop, drops)
|
71
|
+
# Stay within bounds.
|
72
|
+
selected_drop = [ 0,
|
73
|
+
[ drops.size - 1, selected_drop ].min
|
74
|
+
].max
|
75
|
+
|
76
|
+
line = selected_drop * 3
|
77
|
+
mvwaddch win, line, 0, ?>.ord
|
78
|
+
wmove win, line, 0
|
79
|
+
|
80
|
+
selected_drop
|
81
|
+
end
|
82
|
+
|
83
|
+
def pretty_date(date)
|
84
|
+
diff = (Time.now - date.to_time).to_i
|
85
|
+
case diff
|
86
|
+
when 0 then 'just now'
|
87
|
+
when 1 then 'a second ago'
|
88
|
+
when 2..59 then diff.to_s+' seconds ago'
|
89
|
+
when 60..119 then 'a minute ago' #120 = 2 minutes
|
90
|
+
when 120..3540 then (diff/60).to_i.to_s+' minutes ago'
|
91
|
+
when 3541..7100 then 'an hour ago' # 3600 = 1 hour
|
92
|
+
when 7101..82800 then ((diff+99)/3600).to_i.to_s+' hours ago'
|
93
|
+
when 82801..172000 then 'a day ago' # 86400 = 1 day
|
94
|
+
when 172001..518400 then ((diff+800)/(60*60*24)).to_i.to_s+' days ago'
|
95
|
+
when 518400..1036800 then 'a week ago'
|
96
|
+
else ((diff+180000)/(60*60*24*7)).to_i.to_s+' weeks ago'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def popup_window(parent, text)
|
101
|
+
text_width = text.lines.map{ |x| x.size }.max
|
102
|
+
text_height = text.lines.to_a.size
|
103
|
+
rows, cols = getmaxyx parent
|
104
|
+
width = text_width + 4
|
105
|
+
height = text_height + 4
|
106
|
+
col = (cols - width) / 2 - 1
|
107
|
+
row = (rows - height) / 2 - 1
|
108
|
+
|
109
|
+
space = derwin parent, height + 2, width + 2, row, col
|
110
|
+
wclear space
|
111
|
+
|
112
|
+
frame = derwin space, height, width, 1, 1
|
113
|
+
box frame, 0, 0
|
114
|
+
|
115
|
+
win = derwin frame, text_height, text_width, 2, 2
|
116
|
+
wmove win, 0, 0
|
117
|
+
waddstr win, text
|
118
|
+
|
119
|
+
wrefresh space
|
120
|
+
wrefresh frame
|
121
|
+
wrefresh win
|
122
|
+
|
123
|
+
ch = wgetch win
|
124
|
+
flushinp
|
125
|
+
ungetch ch
|
126
|
+
|
127
|
+
delwin win
|
128
|
+
delwin frame
|
129
|
+
delwin space
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
drops = account.drops(limit: 5)
|
134
|
+
|
135
|
+
begin
|
136
|
+
initscr
|
137
|
+
noecho
|
138
|
+
|
139
|
+
win, wrap = draw_drops_window drops
|
140
|
+
selected_drop = select_drop win, 0, drops
|
141
|
+
|
142
|
+
while (c = wgetch(win)) != ?q.ord
|
143
|
+
case c
|
144
|
+
when ?j.ord
|
145
|
+
selected_drop += 1
|
146
|
+
when ?k.ord
|
147
|
+
selected_drop -= 1
|
148
|
+
|
149
|
+
when ?c.ord, KEY_RETURN
|
150
|
+
link = drops[selected_drop].share_url
|
151
|
+
copy link
|
152
|
+
popup_window win, 'Copied share link.'
|
153
|
+
when ?C.ord
|
154
|
+
link = drops[selected_drop].embed_url
|
155
|
+
copy link
|
156
|
+
popup_window win, 'Copied embed link.'
|
157
|
+
when ?d.ord
|
158
|
+
link = drops[selected_drop].download_url
|
159
|
+
copy link
|
160
|
+
popup_window win, 'Copied download link.'
|
161
|
+
when ?t.ord
|
162
|
+
link = drops[selected_drop].thumbnail_url
|
163
|
+
copy link
|
164
|
+
popup_window win, 'Copied thumbnail link.'
|
165
|
+
end
|
166
|
+
|
167
|
+
delwin win
|
168
|
+
win, wrap = draw_drops_window drops
|
169
|
+
selected_drop = select_drop win, selected_drop, drops
|
170
|
+
end
|
171
|
+
|
172
|
+
delwin win
|
173
|
+
|
174
|
+
rescue => e
|
175
|
+
endwin
|
176
|
+
raise
|
177
|
+
ensure
|
178
|
+
endwin
|
179
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.rubygems_version = '1.3.5'
|
11
|
+
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'cloudapp-cli'
|
16
|
+
s.version = '1.0.0.beta.1'
|
17
|
+
s.date = '2012-08-17'
|
18
|
+
s.rubyforge_project = 'cloudapp-cli'
|
19
|
+
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "CloudApp CLI"
|
23
|
+
s.description = "Experience all the pleasures of sharing with CloudApp now in your terminal."
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["Larry Marburger"]
|
29
|
+
s.email = 'larry@marburger.cc'
|
30
|
+
s.homepage = 'https://github.com/cloudapp/cloudapp-cli'
|
31
|
+
|
32
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
+
s.require_paths = %w[lib]
|
35
|
+
|
36
|
+
## If your gem includes any executables, list them here.
|
37
|
+
s.executables = ["cloudapp"]
|
38
|
+
|
39
|
+
## Specify any RDoc options here. You'll want to add your README and
|
40
|
+
## LICENSE files to the extra_rdoc_files list.
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.extra_rdoc_files = %w[README.md MIT-LICENSE]
|
43
|
+
|
44
|
+
## List your runtime dependencies here. Runtime dependencies are those
|
45
|
+
## that are needed for an end user to actually USE your code.
|
46
|
+
s.add_dependency 'cloudapp', '~> 2.0.0.beta.1'
|
47
|
+
s.add_dependency 'ffi-ncurses'
|
48
|
+
s.add_dependency 'highline'
|
49
|
+
|
50
|
+
# Needed for Highline echo=false support as per
|
51
|
+
# https://github.com/JEG2/highline/issues/39
|
52
|
+
s.add_dependency 'ruby-termios'
|
53
|
+
|
54
|
+
## List your development dependencies here. Development dependencies are
|
55
|
+
## those that are only needed during development
|
56
|
+
s.add_development_dependency 'rake'
|
57
|
+
s.add_development_dependency 'ronn'
|
58
|
+
s.add_development_dependency 'rspec'
|
59
|
+
|
60
|
+
## Leave this section as-is. It will be automatically generated from the
|
61
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
62
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
63
|
+
# = MANIFEST =
|
64
|
+
s.files = %w[
|
65
|
+
CHANGELOG.md
|
66
|
+
Gemfile
|
67
|
+
Gemfile.lock
|
68
|
+
MIT-LICENSE
|
69
|
+
README.md
|
70
|
+
Rakefile
|
71
|
+
bin/cloudapp
|
72
|
+
cloudapp-cli.gemspec
|
73
|
+
lib/cloudapp/cli.rb
|
74
|
+
lib/cloudapp/cli/config.rb
|
75
|
+
spec/cloudapp/cli/config_spec.rb
|
76
|
+
spec/helper.rb
|
77
|
+
]
|
78
|
+
# = MANIFEST =
|
79
|
+
|
80
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
81
|
+
## matches what you actually use.
|
82
|
+
# s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
83
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'singleton'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module CloudApp
|
6
|
+
module CLI
|
7
|
+
class Config
|
8
|
+
def initialize(path = File.expand_path('~/.cloudapprc'))
|
9
|
+
@path = path
|
10
|
+
@config = read_config
|
11
|
+
end
|
12
|
+
|
13
|
+
def token
|
14
|
+
@config[:token]
|
15
|
+
end
|
16
|
+
|
17
|
+
def token=(token)
|
18
|
+
if token
|
19
|
+
@config[:token] = token
|
20
|
+
else
|
21
|
+
@config.delete :token
|
22
|
+
end
|
23
|
+
|
24
|
+
write_config
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def read_config
|
30
|
+
return {} unless File.exist?(@path)
|
31
|
+
File.open(@path) {|file| YAML.load(file) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def write_config
|
35
|
+
File.open(@path, 'w', 0600) {|file|
|
36
|
+
YAML.dump @config, file
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/cloudapp/cli.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
require 'cloudapp/cli/config'
|
5
|
+
|
6
|
+
describe CloudApp::CLI::Config do
|
7
|
+
let(:config) { {} }
|
8
|
+
let(:content) { YAML.dump(config) }
|
9
|
+
let(:path) { config_file.path }
|
10
|
+
let(:config_file) {
|
11
|
+
Tempfile.new('cloudapprc', '.').tap do |file|
|
12
|
+
file << content
|
13
|
+
file.flush
|
14
|
+
file.close
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
after do config_file.unlink end
|
19
|
+
|
20
|
+
describe '#new' do
|
21
|
+
subject { CloudApp::CLI::Config.new path }
|
22
|
+
|
23
|
+
describe 'an existing config file' do
|
24
|
+
let(:config) {{ token: 'token' }}
|
25
|
+
|
26
|
+
it 'reads the content' do
|
27
|
+
subject.token.should eq(config[:token])
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'updates a key' do
|
31
|
+
new_token = 'new token'
|
32
|
+
subject.token = new_token
|
33
|
+
expected = YAML.dump token: new_token
|
34
|
+
|
35
|
+
content = File.open(path) {|file| file.read }
|
36
|
+
content.should eq(expected)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'clears a key' do
|
40
|
+
subject.token = nil
|
41
|
+
expected = YAML.dump({})
|
42
|
+
|
43
|
+
content = File.open(path) {|file| file.read }
|
44
|
+
content.should eq(expected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'an empty config file' do
|
49
|
+
it 'returns nil' do
|
50
|
+
subject.token.should be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'a nonexistent config file' do
|
55
|
+
let(:path) { 'nonexistent' }
|
56
|
+
|
57
|
+
it 'returns nil' do
|
58
|
+
subject.token.should be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudapp-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.beta.1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Larry Marburger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cloudapp
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0.beta.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0.beta.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ffi-ncurses
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: highline
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ruby-termios
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rake
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: ronn
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rspec
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Experience all the pleasures of sharing with CloudApp now in your terminal.
|
127
|
+
email: larry@marburger.cc
|
128
|
+
executables:
|
129
|
+
- cloudapp
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files:
|
132
|
+
- README.md
|
133
|
+
- MIT-LICENSE
|
134
|
+
files:
|
135
|
+
- CHANGELOG.md
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- MIT-LICENSE
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- bin/cloudapp
|
142
|
+
- cloudapp-cli.gemspec
|
143
|
+
- lib/cloudapp/cli.rb
|
144
|
+
- lib/cloudapp/cli/config.rb
|
145
|
+
- spec/cloudapp/cli/config_spec.rb
|
146
|
+
- spec/helper.rb
|
147
|
+
homepage: https://github.com/cloudapp/cloudapp-cli
|
148
|
+
licenses: []
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options:
|
151
|
+
- --charset=UTF-8
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>'
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.3.1
|
166
|
+
requirements: []
|
167
|
+
rubyforge_project: cloudapp-cli
|
168
|
+
rubygems_version: 1.8.23
|
169
|
+
signing_key:
|
170
|
+
specification_version: 2
|
171
|
+
summary: CloudApp CLI
|
172
|
+
test_files: []
|