lib/negroku/cli.rb in negroku-0.0.2 vs lib/negroku/cli.rb in negroku-0.0.3
- old
+ new
@@ -18,17 +18,16 @@
config = getConfig
# Test for config
if config.empty?
say "[WARNING]".foreground(:red)
- say "It's recommended that you add some default settings to negroku before you create your app deployment\n\n"
- say "For example you can add your most common git urls using:\n"
- say "negroku repo add git@github.com:yourusername.git\n".foreground(:yellow)
- say "Also you can add your deployment servers urls using:\n"
+ say "It's recommended that you add some custom settings to negroku before you create your app deployment\n\n"
+ say "You can add your deployment servers urls using:\n"
say "negroku target add my.deployment.com".foreground(:yellow)
say "negroku target add 104.284.3.1\n".foreground(:yellow)
- unless yes? "Do you want to continue without adding default settings? [y/N]"
+ unless agree "You have not added custom settings! Do you want to continue? [y/n]", true
+ say "Goodbye"
exit
end
end
say "We're about to create your application deploy setup\n".foreground(:green)
@@ -51,37 +50,22 @@
menu.prompt = "Please choose your repository?".bright()
menu.select_by = :index
# find local remote from git repo
if File.directory?(".git")
- say "[INFO] The first repo was taken from the local git checkout remotes".color(:yellow)
- local_repo = %x(git remote -v | grep origin | grep push | awk '{print $2}').gsub(/\n/,"")
- menu.choice("#{local_repo}") do |command|
- say("Using #{command}")
- data[:repo] = command;
- end
- end
-
- # adds the repos in the config file if there is one
- if config[:repo]
- config[:repo].each do |val|
- repo_url = "#{val}/#{data[:application_name]}.git"
- # skip if the repo url is the same as the local one
- unless repo_url == local_repo
- menu.choice(repo_url) do |command|
- say("Using #{command}/#{data[:application_name]}.git")
- data[:repo] = command;
- end
+ local_repos = %x(git remote -v | awk '{print $2}' | uniq).split("\n")
+ local_repos.each do |url|
+ menu.choice(url) do |command|
+ say("Using #{command}")
+ data[:repo] = command;
end
end
- else
- say "[INFO] There are no repos in the default settings".color(:yellow)
end
# add other repo choice
menu.choice(:other) {
- data[:repo] = ask "Type the url and username e.g. git@github.com:username: ".bright()
+ data[:repo] = ask "Type the url and username e.g. git@github.com:username/app-name.git: ".bright()
}
end
# The application target deploy server
choose do |menu|
@@ -90,11 +74,11 @@
say "=============="
menu.prompt = "Please choose your deployment server?".bright()
menu.select_by = :index
# Adds the targets in the config file if there is one
- if config[:repo]
+ if config[:target]
config[:target].each do |val|
menu.choice(val) do |command|
say("Using #{command}")
data[:target_server] = command;
end
@@ -109,59 +93,43 @@
end
# Add custom domain
say "\nCUSTOM DOMAIN"
say "============="
- if yes? "Do you want to use #{data[:target_server].gsub(/^([a-z\d]*)/, data[:application_name])}? [Y/n]"
+ if agree "Do you want to use #{data[:target_server].gsub(/^([a-z\d]*)/, data[:application_name])}? [y/n]", true
data[:domains] = data[:target_server].gsub(/^([a-z\d]*)/, data[:application_name])
else
data[:domains] = ask "Please enter the domains separated by spaces"
end
init(".", data)
+ puts "[Negroku] => Running capistrano task deploy:setup"
+ `cap deploy:setup`
+
say "\n\nWhat to do next?\n".bright()
- say "You can try with cap -T to see the available tasks"
- say "Also you can check the config/deploy.rb file, you may want to change some things there"
+ say "You can try with " + "cap -T".color(:yellow) +" to see the available tasks"
+ say "Also you can check the " + "config/deploy.rb".color(:yellow) + " file, you may want to change some things there"
+ say "NOTE: If this is the first time the app is deployed, use the task " + "cap deploy:cold task".color(:yellow)
say "\n HAPPY DEPLOY".foreground(:green)
end
desc "deploy", "Deploy the application"
def deploy
put "I will deploy"
end
end
-class Repo < Thor
-
- desc "add", "add new default repositories"
- def add(url=nil)
- if url.nil?
- url = ask("Type the url and username e.g. git@github.com:username")
- end
- saveConfig(:add, :repo, url)
- end
-
- desc "remove", "remove some repo"
- def remove
- puts "I will remove a repo"
- end
-
- desc "list", "show the repost"
- def list
- puts "I will list the target servers"
- end
-end
-
class Target < Thor
desc "add", "add new default target server"
def add(host=nil)
if host.nil?
host = ask("Type the host or ip for the target machine")
end
saveConfig(:add, :target, host)
+ say "[Negroku] Added #{host}"
end
desc "remove", "remove some target"
def remove
puts "I will remove a target"
@@ -200,11 +168,11 @@
if !key.nil? && value.nil?
value = ask("Please enter the value for #{key}:")
# If nothing was sent
elsif key.nil? && value.nil?
# Check if the .rbenv-vars file exists and offer get the info from there
- if File.exist?(".rbenv-vars") && (yes? "Do you want to add variables from your local .rbenv-vars file [y/N]")
+ if File.exist?(".rbenv-vars") && (agree "Do you want to add variables from your local .rbenv-vars file [y/n]", true)
choose do |menu|
menu.prompt = "Please choose variable you want to add?".bright()
menu.select_by = :index
File.readlines(".rbenv-vars").each do |line|
@@ -225,10 +193,9 @@
end
module Negroku
class CLI < Thor
register(App, 'app', 'app [COMMAND]', 'Application')
- register(Repo, 'repo', 'repo [COMMAND]', 'Repositories')
register(Target, 'target', 'target [COMMAND]', 'Target servers')
register(Konfig, 'config', 'config [COMMAND]', 'Configuration')
register(RemoteEnv, 'env', 'env [COMMAND]', 'Remote environmental variables')
end
end
\ No newline at end of file