#!/usr/bin/env ruby lib = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'git/semaphore' require 'slop' options = Slop.parse(help: true) do |o| o.banner = <<~"BANNER" Usage: git-semaphore [options] v#{Git::Semaphore::VERSION} Options: BANNER o.on '--version', 'Print the version' do puts Git::Semaphore::LONG_VERSION exit(0) end o.on '--help', 'Print help message' do puts o exit(0) end o.on '--refresh', 'Bypass cached information and refresh from API' o.on '--projects', 'List all projects and their current status' o.on '--browse', 'Open the project on https://semaphoreci.com/' o.on '--rebuild', 'Rebuild last revision for the current branch' o.on '--settings', 'Display most relevant settings' o.on '--internals', 'Display all internal settings' o.on '--branches', 'List all branches for the current project' o.on '--status', 'List the build status for the current branch' o.on '--history', 'List the build history for the current branch' o.on '--information', 'List the commit information for the last build' o.on '--log', 'List the build log for the last build' end project = if (git_repo = Git::Semaphore.git_repo) Git::Semaphore::Project.from_repo(git_repo) else Git::Semaphore::Project.from_config(ENV) end class SafeProject # rubocop:disable Style/MethodMissing def initialize(project) @project = project end def method_missing(name, *args, &block) if @project.exist? @project.send(name, *args, &block) else { error: "Project #{@project.full_name} doesn't exist on semaphoreci.com" } end end def respond_to?(name, include_all = false) @project.respond_to? name, include_all end # rubocop:enable Style/MethodMissing end project = SafeProject.new(project) refresh = options.refresh? case when options.projects? then puts Git::Semaphore::Project.all(refresh).to_json when options.browse? then puts project.browse.to_json when options.rebuild? then puts project.rebuild.to_json when options.settings? then puts project.settings.to_json when options.internals? then puts project.internals.to_json when options.branches? then puts project.branches(refresh).to_json when options.status? then puts project.status(refresh).to_json when options.history? then puts project.history(refresh).to_json when options.information? then puts project.information(refresh).to_json when options.log? then puts project.log(refresh).to_json else puts options end # That's all Folks!