#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') begin require 'git-semaphore' require 'bundler' Bundler.setup rescue LoadError require 'rubygems' require 'git-semaphore' end options = Trollop::options do version Git::Semaphore::COPYRIGHT banner Git::Semaphore::BANNER opt :projects, 'List all semaphore.app projects', :short => nil, :default => false opt :branches, 'List all semaphore.app branches for current project', :short => nil, :default => false opt :status, 'List the semaphore.app status for the given branch', :short => nil, :default => false opt :'commit-status', 'Check commit status', :default => false opt :'rebuild-last-revision', 'Rebuild last revision', :default => false opt :'working-dir', 'Print working dir', :short => 'w', :default => false opt :'project-name', 'Print project name', :short => 'p', :default => false opt :'branch-name', 'Print branch name', :short => 'b', :default => false opt :'check-auth', 'Check auth token', :short => 'x', :default => false opt :'check-project', 'Check project hash id', :short => 'y', :default => false opt :'check-branch', 'Check branch id', :short => 'z', :default => false opt :'git-config', 'Print git settings', :short => 'g', :default => false opt :'env-config', 'Print environment settings', :short => 'e', :default => false end app = Git::Semaphore::App.new(Dir.pwd, ENV) if !app.validate r = app.git_repo rescue false unless r STDERR.puts "Error: \"#{Dir.pwd}\" is not a git working directory... exiting!" exit 255 end end if options[:'rebuild-last-revision'] puts app.rebuild_last_revision exit 0 end if options[:'commit-status'] puts app.commit_status exit 0 end if options[:projects] puts app.projects exit 0 end if options[:branches] puts app.branches exit 0 end if options[:status] puts app.status exit 0 end if options[:'working-dir'] puts app.working_dir exit 0 end if options[:'project-name'] puts app.project_name exit 0 end if options[:'branch-name'] puts app.branch_name exit 0 end if options[:'check-auth'] unless app.auth_token STDERR.puts 'Please set - and export - the SEMAPHORE_AUTH_TOKEN env variable' STDERR.puts 'Alternatively, set semaphore.authtoken in your local git config' exit -1 else exit 0 end end if options[:'check-project'] unless app.project_token STDERR.puts 'Please set - and export - the SEMAPHORE_PROJECT_TOKEN env variable' STDERR.puts 'Alternatively, set semaphore.projecttoken in your local git config' exit -1 else exit 0 end end if options[:'env-config'] puts "export SEMAPHORE_AUTH_TOKEN=\"#{app.env_auth_token}\"" puts "export SEMAPHORE_PROJECT_TOKEN=\"#{app.env_project_token}\"" exit 0 end if options[:'git-config'] puts "git config --local --replace-all semaphore.authtoken \"#{app.git_auth_token}\"" puts "git config --local --replace-all semaphore.projecttoken \"#{app.git_project_token}\"" exit 0 end fail "Coming soon!" # That's all, Folks!