tane 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/README.md +22 -0
- data/Rakefile +10 -0
- data/bin/tane +18 -0
- data/lib/tane.rb +64 -0
- data/lib/tane/commands/app.rb +5 -0
- data/lib/tane/commands/base.rb +15 -0
- data/lib/tane/commands/claim.rb +26 -0
- data/lib/tane/commands/create.rb +46 -0
- data/lib/tane/commands/email.rb +50 -0
- data/lib/tane/commands/event.rb +21 -0
- data/lib/tane/commands/exec.rb +37 -0
- data/lib/tane/commands/help.rb +33 -0
- data/lib/tane/commands/init.rb +25 -0
- data/lib/tane/commands/login.rb +91 -0
- data/lib/tane/commands/logout.rb +25 -0
- data/lib/tane/commands/refresh.rb +26 -0
- data/lib/tane/commands/signup.rb +43 -0
- data/lib/tane/commands/support.rb +37 -0
- data/lib/tane/helpers.rb +168 -0
- data/lib/tane/helpers/bushido_helper.rb +50 -0
- data/lib/tane/helpers/init_helper.rb +116 -0
- data/lib/tane/parser.rb +52 -0
- data/lib/tane/version.rb +3 -0
- data/spec/commands/base_spec.rb +26 -0
- data/spec/commands/claim_spec.rb +31 -0
- data/spec/commands/email_spec.rb +71 -0
- data/spec/commands/event_spec.rb +20 -0
- data/spec/commands/exec_spec.rb +18 -0
- data/spec/commands/help_spec.rb +12 -0
- data/spec/commands/init_spec.rb +27 -0
- data/spec/commands/login_spec.rb +81 -0
- data/spec/commands/support_spec.rb +59 -0
- data/spec/executable_spec.rb +11 -0
- data/spec/fixtures/credentials.yml +2 -0
- data/spec/helpers/bushido_helper_spec.rb +87 -0
- data/spec/helpers/init_helper_spec.rb +127 -0
- data/spec/helpers_spec.rb +223 -0
- data/spec/spec_helper.rb +15 -0
- data/tane.gemspec +29 -0
- data/tasks/spec.rake +10 -0
- data/tasks/tane.rake +11 -0
- metadata +188 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Tane
|
2
|
+
|
3
|
+
Copy-paste the following to create a new Bushido rails application.
|
4
|
+
|
5
|
+
gem install tane
|
6
|
+
tane create
|
7
|
+
|
8
|
+
## What is tane?
|
9
|
+
|
10
|
+
Tane is a Bushido Developers best friend and a development tool. It
|
11
|
+
helps you generate new Bushido capable apps. It also enables existing
|
12
|
+
Ruby on Rails Apps to be Bushido friendly.
|
13
|
+
|
14
|
+
## How To Create A New App
|
15
|
+
|
16
|
+
Install the tane gem and run the `tane create` command to create a new
|
17
|
+
app.
|
18
|
+
|
19
|
+
The create command will then make a new directory using that passed
|
20
|
+
name. If you don't pass a name, it will ask you for one. The create
|
21
|
+
command will use the directory specified to generate a new rails 3 app
|
22
|
+
based on a Bushido app template.
|
data/Rakefile
ADDED
data/bin/tane
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
args = ARGV.dup
|
9
|
+
ARGV.clear
|
10
|
+
|
11
|
+
require 'tane'
|
12
|
+
options = Tane::Parser.parse(args)
|
13
|
+
|
14
|
+
command = args.shift.strip rescue 'help'
|
15
|
+
command = 'help' if command == ''
|
16
|
+
|
17
|
+
klass = Tane::Commands.const_get command.capitalize
|
18
|
+
klass.fire(options, args)
|
data/lib/tane.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "optparse"
|
3
|
+
require "awesome_print"
|
4
|
+
require "highline"
|
5
|
+
|
6
|
+
require "tane/version"
|
7
|
+
require "tane/helpers"
|
8
|
+
require "tane/parser"
|
9
|
+
|
10
|
+
# Load all the available commands
|
11
|
+
$commands = []
|
12
|
+
|
13
|
+
Dir.glob(File.dirname(__FILE__) + "/tane/commands/*.rb").each do |command|
|
14
|
+
$commands << command.split("/").last.split('.rb').first
|
15
|
+
end
|
16
|
+
|
17
|
+
# Mark the commands for autoload (load-on-demand)
|
18
|
+
module Tane
|
19
|
+
module Commands
|
20
|
+
$commands.each do |command|
|
21
|
+
autoload command.capitalize.to_sym, "tane/commands/#{command}"
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def command_list_and_help
|
26
|
+
command_list = "\n"
|
27
|
+
command_list += "The commands I know are:"
|
28
|
+
|
29
|
+
($commands - ["app", "base"]).each do |command|
|
30
|
+
command_list += "\n #{command}"
|
31
|
+
end
|
32
|
+
|
33
|
+
command_list += "\n\n"
|
34
|
+
command_list += "For help on any of these commands do"
|
35
|
+
command_list += "\n\t"
|
36
|
+
command_list += "tane help command_name"
|
37
|
+
command_list += "\n\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def const_missing(name)
|
41
|
+
puts "Unsupported command #{name.downcase}."
|
42
|
+
puts command_list_and_help
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
$helpers = []
|
51
|
+
|
52
|
+
Dir.glob(File.dirname(__FILE__) + "/tane/helpers/*.rb").each do |helper|
|
53
|
+
$helpers << helper.split("/").last.split('_helper.rb').first
|
54
|
+
end
|
55
|
+
|
56
|
+
# Mark the commands for autoload (load-on-demand)
|
57
|
+
module Tane
|
58
|
+
module Helpers
|
59
|
+
$helpers.each do |helper|
|
60
|
+
autoload helper.capitalize.to_sym, "tane/helpers/#{helper}_helper"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Tane::Commands::Claim < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
email = args.first
|
6
|
+
ido_id = args[1]
|
7
|
+
event = {'category' => 'app', 'event' => 'claimed',
|
8
|
+
'data' => {'time' => Time.now, 'ido_id' => ido_id, 'email' => email}}
|
9
|
+
|
10
|
+
post(data_url, event)
|
11
|
+
end
|
12
|
+
|
13
|
+
def help_text
|
14
|
+
<<-EOL
|
15
|
+
Usage:
|
16
|
+
|
17
|
+
tane claim email ido_id
|
18
|
+
|
19
|
+
Notifies the app of an App.claimed event to the locally running app when the email and ido_id are passed.
|
20
|
+
|
21
|
+
tane claim john@example.com 6h284ah92jcj9m2sv21f
|
22
|
+
EOL
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Tane::Commands::Create < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
authenticate_user
|
6
|
+
app_name = args[0] ||= term.ask("Please enter a name for your new app: ") { |app_name| app_name }
|
7
|
+
template_url = ENV['KIMONO_URL'] || "https://raw.github.com/Bushido/kimono/master/kimono.rb"
|
8
|
+
|
9
|
+
print "Creating a new Bushido rails app in #{ app_name } ... "
|
10
|
+
|
11
|
+
system("rails new #{app_name} -m #{ template_url } > tane.log")
|
12
|
+
|
13
|
+
Dir.chdir("./#{app_name}")do
|
14
|
+
system("bundle exec tane init > ../tane.log")
|
15
|
+
end
|
16
|
+
|
17
|
+
success_messages = ["Let the hacking commence!",
|
18
|
+
"Hacks and glory await!",
|
19
|
+
"Hack and be merry!",
|
20
|
+
"Your hacking starts... NOW!",
|
21
|
+
"May the source be with you!",
|
22
|
+
"Take this demi-REPL, dear friend, and may it serve you well.",
|
23
|
+
"Lemonodor-fame is but a hack away!",
|
24
|
+
"Go forth to #{ app_name }, and hack for all you're worth - for all mankind!"]
|
25
|
+
|
26
|
+
success_message = success_messages[ rand(success_messages.length) ]
|
27
|
+
|
28
|
+
FileUtils.mv("./tane.log", "./#{ app_name }/log/tane.log")
|
29
|
+
puts "Finished successfully!"
|
30
|
+
puts "Your app is now in ./#{ app_name } . #{ success_message }"
|
31
|
+
end
|
32
|
+
|
33
|
+
def help_text
|
34
|
+
<<-EOL
|
35
|
+
Usage:
|
36
|
+
|
37
|
+
tane claim email ido_id
|
38
|
+
|
39
|
+
Notifies the app of an App.claimed event to the locally running app when the email and ido_id are passed.
|
40
|
+
|
41
|
+
tane claim john@example.com 6h284ah92jcj9m2sv21f
|
42
|
+
EOL
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Tane::Commands::Email < Tane::Commands::Base
|
2
|
+
class << self
|
3
|
+
def process(args)
|
4
|
+
if args.count == 0
|
5
|
+
list_email_templates
|
6
|
+
else
|
7
|
+
send_email(args.first)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_email_templates
|
12
|
+
email_templates = Dir["#{email_templates_path}/*.yml"]
|
13
|
+
"#{email_templates.count} email templates found for this app:"
|
14
|
+
email_templates.each { |template| term.say template }
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_email(email_name)
|
18
|
+
email = render_email(email_name)
|
19
|
+
|
20
|
+
if email.nil?
|
21
|
+
term.say "Couldn't find any email with the title '#{email_name}', are you sure there is a .bushido/emails/#{email_name}.yml? "
|
22
|
+
term.say "Here are the email templates for this app..."
|
23
|
+
list_email_templates
|
24
|
+
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
post(mail_url, email)
|
29
|
+
end
|
30
|
+
|
31
|
+
def render_email(name)
|
32
|
+
YAML.load(ERB.new(File.read( email_template_file_path(name) )).result)
|
33
|
+
end
|
34
|
+
|
35
|
+
def help_text
|
36
|
+
<<-EOL
|
37
|
+
Usage:
|
38
|
+
|
39
|
+
tane email [email_template_name]
|
40
|
+
|
41
|
+
Simulates an incoming email event in the app running locally, using the template provided. Details on how to create a template are discussed later in this document.
|
42
|
+
|
43
|
+
To list email templates defined for the application, run
|
44
|
+
|
45
|
+
tane email
|
46
|
+
EOL
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Tane::Commands::Event < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
event = {'category' => args.first, 'event' => args[1], 'data' => eval(args[2])}
|
6
|
+
puts event
|
7
|
+
post(data_url, event)
|
8
|
+
end
|
9
|
+
|
10
|
+
def help_text
|
11
|
+
<<-EOL
|
12
|
+
Usage:
|
13
|
+
|
14
|
+
tane event event_category event_name data_hash
|
15
|
+
|
16
|
+
Notifies the local app of an event. The event category, event name are to be passed along with the data. The data is in the form of a ruby hash with the keys as strings (not symbols!). The following is an example.
|
17
|
+
EOL
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Tane::Commands::Exec < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
authenticate_user
|
6
|
+
bushido_envs.each_pair do |key, value|
|
7
|
+
ENV[key] = value
|
8
|
+
end
|
9
|
+
|
10
|
+
command = args.join(' ')
|
11
|
+
|
12
|
+
if command.empty?
|
13
|
+
term.say("please enter a command for tane exec to run. example:")
|
14
|
+
term.say("\t tane exec rails s")
|
15
|
+
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
|
19
|
+
exec command
|
20
|
+
end
|
21
|
+
|
22
|
+
def help_text
|
23
|
+
<<-EOL
|
24
|
+
Usage:
|
25
|
+
|
26
|
+
tane exec any_command
|
27
|
+
|
28
|
+
Executes any command specified in a simulated Bushido environment. The following example shows you how to run rails applications.
|
29
|
+
|
30
|
+
tane exec rails s
|
31
|
+
|
32
|
+
This is how you should be running Bushido rails applications locally. All the configuration required for `tane exec` is obtained from `.bushido` directory in the current directory. This can only be used if `tane init` has been run in the current directory.
|
33
|
+
EOL
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Tane::Commands::Help < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
if args.count == 0
|
6
|
+
puts opts.help_text
|
7
|
+
return
|
8
|
+
end
|
9
|
+
help_for_command args.first.capitalize if args.count != 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def help_for_command(command)
|
13
|
+
klass = Tane::Commands.const_get(command)
|
14
|
+
Tane::Commands.const_missing(command) if not klass.respond_to? :help_text
|
15
|
+
term.say "\n#{klass.help_text}\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
def help_text
|
19
|
+
<<-EOL
|
20
|
+
Usage:
|
21
|
+
|
22
|
+
tane help [command]
|
23
|
+
|
24
|
+
Displays the help message with the list commands tane supports. For details about usage about each each command use `tane help name`, where _name_ is the name of the command you need information about. For example
|
25
|
+
|
26
|
+
tane help support
|
27
|
+
|
28
|
+
displays the information about the support command.
|
29
|
+
EOL
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Tane::Commands::Init < Tane::Commands::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def process(args)
|
5
|
+
authenticate_user
|
6
|
+
if in_rails_dir?
|
7
|
+
Tane::Helpers::Init.initialize_app
|
8
|
+
else
|
9
|
+
term.say("You have to be in the local rails app's root directory when running `tane init`")
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def help_text
|
15
|
+
<<-EOL
|
16
|
+
Usage:
|
17
|
+
|
18
|
+
tane init
|
19
|
+
|
20
|
+
Creates a `.bushido` directory within the directory of the rails application. That holds all the config that enables you to run applications and commands in a Bushido environment. It also deploys a development application on Bushido that allows your local application to use resources on the Bushido platform.
|
21
|
+
EOL
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'tane/commands/app'
|
2
|
+
|
3
|
+
class Tane::Commands::Login < Tane::Commands::Base
|
4
|
+
class << self
|
5
|
+
def process(args)
|
6
|
+
email, password = warn_if_credentials_and_prompt
|
7
|
+
|
8
|
+
auth_token = verify_or_signup(email, password)
|
9
|
+
|
10
|
+
term.say "Done!"
|
11
|
+
term.say "Saving credentials"
|
12
|
+
save_credentials(email, auth_token)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def warn_if_credentials_and_prompt
|
17
|
+
warn_if_credentials
|
18
|
+
|
19
|
+
term.say "Let's log you in:"
|
20
|
+
email, password = prompt_for_credentials
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def verify_or_signup(email, password)
|
25
|
+
term.say "contacting bushido, please wait..."
|
26
|
+
auth_token, errors = Tane::Helpers::Bushido.verify_credentials(email, password)
|
27
|
+
|
28
|
+
return auth_token if not auth_token.nil?
|
29
|
+
|
30
|
+
if auth_token.nil?
|
31
|
+
term.say("Invalid username, or password, sorry! Don't worry though, we'll get you through this!")
|
32
|
+
|
33
|
+
# returns auth_token on success
|
34
|
+
return signup_and_notify(email, password) if term.agree("would you like to try signing up with those credentials?")
|
35
|
+
|
36
|
+
display_help_messages_and_exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def signup_and_notify(email, password)
|
42
|
+
term.say "Trying to sign up with those credentials..."
|
43
|
+
auth_token, errors = Tane::Helpers::Bushido.signup(email, password)
|
44
|
+
|
45
|
+
display_errors_and_exit(errors) if auth_token.nil?
|
46
|
+
|
47
|
+
term.say "Ok, you're signed up as #{email}!"
|
48
|
+
return auth_token
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def display_errors_and_exit(errors)
|
53
|
+
term.say "Couldn't signup - "
|
54
|
+
|
55
|
+
errors.each do |field|
|
56
|
+
term.say "\n"
|
57
|
+
field.last.each do |error|
|
58
|
+
term.say " #{field.first} #{error} \n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def display_help_messages_and_exit
|
66
|
+
messages = [
|
67
|
+
"Please try one of the following:",
|
68
|
+
"\t1. Log in again with different credentials",
|
69
|
+
"\t2. Send us a help message from the command line via `tane support 'Hey guys, having trouble logging in with tane...'`",
|
70
|
+
"\t3. Contact us by email at support@gobushido.com if you're having trouble!",
|
71
|
+
"Seriously, isn't it cool to be able to send a support message straight from the cli? It's like you're the fonz"]
|
72
|
+
|
73
|
+
messages.each do |message|
|
74
|
+
term.say message
|
75
|
+
end
|
76
|
+
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
def help_text
|
81
|
+
<<-EOL
|
82
|
+
Usage:
|
83
|
+
|
84
|
+
tane login
|
85
|
+
|
86
|
+
Logs you into the Bushido and stores the credentials in `~/.bushido/credentials.yml` file. It only stores your email and an authentication token. Your password is not stored. This is required if you want to run local applications in a Bushido environment. It prompts you to signup if you do not have a Bushido account.
|
87
|
+
EOL
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|