fallcli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE.md +22 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/fallcli +7 -0
- data/fallcli.gemspec +35 -0
- data/lib/fallcli.rb +6 -0
- data/lib/fallcli/browser_helper.rb +29 -0
- data/lib/fallcli/cli.rb +69 -0
- data/lib/fallcli/config.rb +69 -0
- data/lib/fallcli/middleware.rb +55 -0
- data/lib/fallcli/middleware/ask_for_credentials.rb +39 -0
- data/lib/fallcli/middleware/base.rb +28 -0
- data/lib/fallcli/middleware/browser.rb +92 -0
- data/lib/fallcli/middleware/check_configuration.rb +18 -0
- data/lib/fallcli/middleware/check_credentials.rb +27 -0
- data/lib/fallcli/middleware/inject_client.rb +27 -0
- data/lib/fallcli/middleware/inject_configuration.rb +15 -0
- data/lib/fallcli/middleware/upload_browser.rb +128 -0
- data/lib/fallcli/uploader_browser_helper.rb +29 -0
- data/lib/fallcli/version.rb +3 -0
- data/spec/cli/account.rb +24 -0
- data/spec/cli/authorize_spec.rb +46 -0
- data/spec/cli/help_cli_spec.rb +17 -0
- data/spec/cli/verify_spec.rb +33 -0
- data/spec/cli/version_cli_spec.rb +16 -0
- data/spec/config_spec.rb +70 -0
- data/spec/fixtures/verify_success.json +14 -0
- data/spec/middleware/base_spec.rb +15 -0
- data/spec/middleware/check_configuration_spec.rb +16 -0
- data/spec/middleware/inject_configuration_spec.rb +16 -0
- data/spec/shared/environment.rb +44 -0
- data/spec/spec_helper.rb +30 -0
- data/tmp/.gitkeep +0 -0
- metadata +247 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ba9483a4dca769bd5b81f3e085a81002d1bf187
|
4
|
+
data.tar.gz: f192f00a01c5c3ea3a76223b35066bc81338fa82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e612c373df9e6a0f3c3822401e6400e7c6cd31ba63c63ce8ffbf16ff93bef8cd6338c777b707c699c451dab1a4e7ac1d7f6f624bab3b28432d8a66708d5a67d4
|
7
|
+
data.tar.gz: 9de372728cbdfe3b54a56846f69f8aa2dc5b4d577a51abec21627d5f43124e0b91031480b1372b6c7f857ce9e5194e4e345e62c7fdf3832e87b2f57956d5507c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Peter Souter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# FallCLI
|
2
|
+
[![Build Status](https://travis-ci.org/petems/fallcli.svg)](https://travis-ci.org/petems/fallcli)
|
3
|
+
|
4
|
+
A hack for the [London Dropbox Hackathon](http://lanyrd.com/2015/london-dropbox-hackathon/)
|
5
|
+
|
6
|
+
I'm probably going to refactor this into [Slipsquare](https://github.com/petems/slipsquare) in the future, as I recycled a lot of code :smile:
|
7
|
+
|
8
|
+
### Installation
|
9
|
+
|
10
|
+
gem install fallcli
|
11
|
+
|
12
|
+
### Configuration
|
13
|
+
|
14
|
+
Run the configuration utility, `fallcli authorize`.
|
15
|
+
|
16
|
+
### File browser
|
17
|
+
|
18
|
+
```
|
19
|
+
$ fallcli browser
|
20
|
+
```
|
21
|
+
|
22
|
+
Screenshot:
|
23
|
+
![screenshot 2015-01-25 06 02 36](https://cloud.githubusercontent.com/assets/1064715/5890542/2949c490-a458-11e4-9e4c-935f6c623f77.png)
|
24
|
+
|
25
|
+
### Upload Browser
|
26
|
+
|
27
|
+
```
|
28
|
+
$ slipsquare uploader-browser
|
29
|
+
```
|
30
|
+
|
31
|
+
Screenshot:
|
32
|
+
![screenshot 2015-01-25 06 04 05](https://cloud.githubusercontent.com/assets/1064715/5890539/24dfc6e8-a458-11e4-8114-8f740f59db70.png)
|
33
|
+
|
34
|
+
## Help
|
35
|
+
|
36
|
+
For a complete overview of all of the available commands, run:
|
37
|
+
|
38
|
+
$ slipsquare help
|
39
|
+
|
40
|
+
Feel free to open issues in case of bugs or improvments.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
See the [contributing guide](CONTRIBUTING.md). Pull-requests welcome!
|
45
|
+
|
data/Rakefile
ADDED
data/bin/fallcli
ADDED
data/fallcli.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fallcli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "fallcli"
|
8
|
+
gem.version = FallCli::VERSION
|
9
|
+
gem.authors = ["Peter Souter"]
|
10
|
+
gem.email = ["p.morsou@gmail.com"]
|
11
|
+
gem.description = %q{A curses CLI app for Dropbox}
|
12
|
+
gem.summary = %q{FallCli is a curses CLI app for Dropbox}
|
13
|
+
gem.homepage = "https://github.com/petems/fallcli"
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency "thor", "~> 0.18.1"
|
22
|
+
gem.add_dependency "middleware" , "~> 0.1.0"
|
23
|
+
|
24
|
+
gem.add_dependency "dropbox-api-petems", "1.1.0"
|
25
|
+
gem.add_dependency "dispel", "0.0.7"
|
26
|
+
gem.add_dependency "ruby-progressbar", "~> 1.2.0"
|
27
|
+
|
28
|
+
gem.add_development_dependency "rake", "~> 10.1.0"
|
29
|
+
gem.add_development_dependency "rspec-core", "~> 2.13.0"
|
30
|
+
gem.add_development_dependency "rspec-expectations", "~> 2.13.0"
|
31
|
+
gem.add_development_dependency "rspec-mocks", "~> 2.13.0"
|
32
|
+
gem.add_development_dependency "webmock", "~> 1.11.0"
|
33
|
+
gem.add_development_dependency "coveralls", "~> 0.7.1"
|
34
|
+
|
35
|
+
end
|
data/lib/fallcli.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module FallCli
|
2
|
+
class BrowserHelper
|
3
|
+
attr_accessor :position
|
4
|
+
|
5
|
+
def initialize items
|
6
|
+
@files = Array.new
|
7
|
+
items.each { |item| @files << item }
|
8
|
+
@position = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def show_files
|
12
|
+
@files.each_with_index.map do |item, index|
|
13
|
+
position == index ? "[#{pretty_dropbox_file(item)}]" : " #{pretty_dropbox_file(item)} "
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def pretty_dropbox_file file
|
18
|
+
"#{file.path} | #{file.mime_type} | #{file.size}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def position_up
|
22
|
+
@position -= 1 unless @position < 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def position_down
|
26
|
+
@position += 1 unless @position == (@files.size - 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/fallcli/cli.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module FallCli
|
4
|
+
autoload :Middleware, "fallcli/middleware"
|
5
|
+
|
6
|
+
class CLI < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
ENV['THOR_COLUMNS'] = '120'
|
9
|
+
|
10
|
+
!check_unknown_options
|
11
|
+
|
12
|
+
map "--version" => :version,
|
13
|
+
"-v" => :version
|
14
|
+
|
15
|
+
desc "help [COMMAND]", "Describe commands or a specific command"
|
16
|
+
def help(meth=nil)
|
17
|
+
super
|
18
|
+
if !meth
|
19
|
+
say "To learn more or to contribute, please see github.com/petems/fallcli"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "authorize", "Authorize a Dropbox account with fallcli"
|
24
|
+
long_desc "This takes you through a workflow for adding configuration
|
25
|
+
details to fallcli."
|
26
|
+
def authorize
|
27
|
+
Middleware.sequence_authorize.call({})
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "browser", "Run the browser"
|
31
|
+
long_desc "This is the file browser that renders a CLI to browse your Dropbox
|
32
|
+
files, and you can navigate using the arrow keys"
|
33
|
+
def browser
|
34
|
+
Middleware.sequence_browser.call({})
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "uploader-browser", "Run the upload-browser"
|
38
|
+
long_desc "This is the file browser that renders your local file system files
|
39
|
+
files, and you can upload with the CLI"
|
40
|
+
def uploader_browser
|
41
|
+
Middleware.sequence_upload_browser.call({})
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "verify", "Check your given credentials are valid"
|
45
|
+
long_desc "This checks that the credentials in ~/.fallcli are correct"
|
46
|
+
def verify
|
47
|
+
Middleware.sequence_verify.call({})
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "get-keys", "Get your app and secret keys"
|
51
|
+
def get_keys
|
52
|
+
say "Please open this URL from your Browser, and login: https://www.dropbox.com/developers/apps"
|
53
|
+
say "Click \"Create app\" button, and choose the following options:"
|
54
|
+
say "Type: Dropbox API app"
|
55
|
+
say "Data: Files and Datastores"
|
56
|
+
say "Permission type: Full Dropbox"
|
57
|
+
say "File Types: All file types"
|
58
|
+
say "App name: FallCli#{Time.now.to_i}"
|
59
|
+
say "Cick on the \"Create\" button, and note down the 'app key' and 'app secret'"
|
60
|
+
end
|
61
|
+
|
62
|
+
desc "version", "Show version"
|
63
|
+
def version
|
64
|
+
say "FallCli #{FallCli::VERSION}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module FallCli
|
5
|
+
# This is the configuration object. It reads in configuration
|
6
|
+
# from a .fallcli file located in the user's home directory
|
7
|
+
|
8
|
+
class Configuration
|
9
|
+
include Singleton
|
10
|
+
attr_reader :data
|
11
|
+
attr_reader :path
|
12
|
+
|
13
|
+
FILE_NAME = '.fallcli/config'
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@path = ENV["FALLCLI_CONFIG_PATH"] || File.join(File.expand_path("~"), FILE_NAME)
|
17
|
+
@data = self.load_config_file
|
18
|
+
end
|
19
|
+
|
20
|
+
# If we can't load the config file, self.data is nil, which we can
|
21
|
+
# check for in CheckConfiguration
|
22
|
+
def load_config_file
|
23
|
+
require 'yaml'
|
24
|
+
YAML.load_file(@path)
|
25
|
+
rescue Errno::ENOENT
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
def app_key
|
30
|
+
@data['authentication']['app_key']
|
31
|
+
end
|
32
|
+
|
33
|
+
def secret_key
|
34
|
+
@data['authentication']['secret_key']
|
35
|
+
end
|
36
|
+
|
37
|
+
def app_token
|
38
|
+
@data['client']['app_token']
|
39
|
+
end
|
40
|
+
|
41
|
+
def app_secret
|
42
|
+
@data['client']['app_secret']
|
43
|
+
end
|
44
|
+
|
45
|
+
# Re-runs initialize
|
46
|
+
def reset!
|
47
|
+
self.send(:initialize)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Re-loads the config
|
51
|
+
def reload!
|
52
|
+
@data = self.load_config_file
|
53
|
+
end
|
54
|
+
|
55
|
+
# Writes a config file
|
56
|
+
def create_config_file(app_key, secret_key, app_token, app_secret)
|
57
|
+
FileUtils.mkdir_p File.join(File.expand_path("~"),'.fallcli/')
|
58
|
+
require 'yaml'
|
59
|
+
File.open(@path, File::RDWR|File::TRUNC|File::CREAT, 0600) do |file|
|
60
|
+
data = {
|
61
|
+
"authentication" => { "app_key" => app_key, "secret_key" => secret_key },
|
62
|
+
"client" => { "app_token" => app_token, "app_secret" => app_secret }
|
63
|
+
}
|
64
|
+
file.write data.to_yaml
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "middleware"
|
2
|
+
|
3
|
+
module FallCli
|
4
|
+
module Middleware
|
5
|
+
autoload :Base, "fallcli/middleware/base"
|
6
|
+
|
7
|
+
autoload :AskForCredentials, "fallcli/middleware/ask_for_credentials"
|
8
|
+
autoload :Browser, "fallcli/middleware/browser"
|
9
|
+
autoload :CheckConfiguration, "fallcli/middleware/check_configuration"
|
10
|
+
autoload :CheckCredentials, "fallcli/middleware/check_credentials"
|
11
|
+
autoload :InjectClient, "fallcli/middleware/inject_client"
|
12
|
+
autoload :InjectConfiguration, "fallcli/middleware/inject_configuration"
|
13
|
+
autoload :UploaderBrowser, "fallcli/middleware/upload_browser"
|
14
|
+
|
15
|
+
def self.sequence_authorize
|
16
|
+
::Middleware::Builder.new do
|
17
|
+
use InjectConfiguration
|
18
|
+
use AskForCredentials
|
19
|
+
use InjectConfiguration
|
20
|
+
use CheckConfiguration
|
21
|
+
use InjectClient
|
22
|
+
use CheckCredentials
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.sequence_browser
|
27
|
+
::Middleware::Builder.new do
|
28
|
+
use InjectConfiguration
|
29
|
+
use CheckConfiguration
|
30
|
+
use InjectClient
|
31
|
+
use Browser
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.sequence_upload_browser
|
36
|
+
::Middleware::Builder.new do
|
37
|
+
use InjectConfiguration
|
38
|
+
use CheckConfiguration
|
39
|
+
use InjectClient
|
40
|
+
use CheckCredentials
|
41
|
+
use UploaderBrowser
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.sequence_verify
|
46
|
+
::Middleware::Builder.new do
|
47
|
+
use InjectConfiguration
|
48
|
+
use CheckConfiguration
|
49
|
+
use InjectClient
|
50
|
+
use CheckCredentials
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "dropbox-api"
|
2
|
+
require "cgi"
|
3
|
+
|
4
|
+
module FallCli
|
5
|
+
module Middleware
|
6
|
+
# Ask for user credentials from the command line, then write them out.
|
7
|
+
class AskForCredentials < Base
|
8
|
+
def call(env)
|
9
|
+
|
10
|
+
say "If you dont know your app and secret key, try `fallcli get-keys`"
|
11
|
+
|
12
|
+
app_key = ask "Enter your App key:"
|
13
|
+
secret_key = ask "Enter your Secret key:"
|
14
|
+
|
15
|
+
Dropbox::API::Config.app_key = app_key
|
16
|
+
Dropbox::API::Config.app_secret = secret_key
|
17
|
+
|
18
|
+
consumer = Dropbox::API::OAuth.consumer(:authorize)
|
19
|
+
request_token = consumer.get_request_token
|
20
|
+
say "Go to this url and click 'Authorize' to get the token:"
|
21
|
+
say request_token.authorize_url, :green
|
22
|
+
query = request_token.authorize_url.split('?').last
|
23
|
+
params = CGI.parse(query)
|
24
|
+
token = params['oauth_token'].first
|
25
|
+
yes? "Once you authorize the app on Dropbox, type yes... "
|
26
|
+
access_token = request_token.get_access_token(:oauth_verifier => token)
|
27
|
+
|
28
|
+
# Write the config file.
|
29
|
+
env['config'].create_config_file(app_key, secret_key, access_token.token, access_token.secret)
|
30
|
+
env['config'].reload!
|
31
|
+
|
32
|
+
say "Credentials saved to ~/.fallcli"
|
33
|
+
|
34
|
+
@app.call(env)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FallCli
|
2
|
+
module Middleware
|
3
|
+
# A base middleware class to initalize.
|
4
|
+
class Base
|
5
|
+
# Some colors for making things pretty.
|
6
|
+
CLEAR = "\e[0m"
|
7
|
+
RED = "\e[31m"
|
8
|
+
GREEN = "\e[32m"
|
9
|
+
YELLOW = "\e[33m"
|
10
|
+
|
11
|
+
# We want access to all of the fun thor cli helper methods,
|
12
|
+
# like say, yes?, ask, etc.
|
13
|
+
include Thor::Shell
|
14
|
+
|
15
|
+
def initialize(app)
|
16
|
+
@app = app
|
17
|
+
# This resets the color to "clear" on the user's terminal.
|
18
|
+
say "", :clear, false
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(env)
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|