Module: Semaph

Defined in:
lib/semaph.rb,
lib/semaph/client.rb,
lib/semaph/version.rb,
lib/semaph/commands.rb,
lib/semaph/model/job.rb,
lib/semaph/formatting.rb,
lib/semaph/model/project.rb,
lib/semaph/model/pipeline.rb,
lib/semaph/model/workflow.rb,
lib/semaph/model/promotion.rb,
lib/semaph/model/job_collection.rb,
lib/semaph/commands/reload_command.rb,
lib/semaph/model/project_collection.rb,
lib/semaph/model/pipeline_collection.rb,
lib/semaph/model/workflow_collection.rb,
lib/semaph/commands/visit_url_command.rb,
lib/semaph/model/promotion_collection.rb,
lib/semaph/shells/project/save_command.rb,
lib/semaph/shells/project/project_shell.rb,
lib/semaph/commands/stop_workflow_command.rb,
lib/semaph/shells/pipeline/pipeline_shell.rb,
lib/semaph/shells/workflow/workflow_shell.rb,
lib/semaph/commands/rerun_workflow_command.rb,
lib/semaph/shells/pipeline/job_log_command.rb,
lib/semaph/shells/pipeline/promote_command.rb,
lib/semaph/shells/pipeline/job_show_command.rb,
lib/semaph/shells/pipeline/job_stop_command.rb,
lib/semaph/shells/pipeline/job_debug_command.rb,
lib/semaph/shells/pipeline/jobs_list_command.rb,
lib/semaph/shells/pipeline/jobs_poll_command.rb,
lib/semaph/shells/pipeline/job_log_grep_command.rb,
lib/semaph/shells/project/workflows_list_command.rb,
lib/semaph/shells/organisation/organisation_shell.rb,
lib/semaph/shells/workflow/pipelines_list_command.rb,
lib/semaph/shells/pipeline/promotions_list_command.rb,
lib/semaph/shells/project/workflows_select_command.rb,
lib/semaph/shells/organisations/organisations_shell.rb,
lib/semaph/shells/workflow/pipelines_select_command.rb,
lib/semaph/shells/organisation/projects_list_command.rb,
lib/semaph/shells/organisation/projects_select_command.rb,
lib/semaph/shells/organisations/organisations_list_command.rb,
lib/semaph/shells/organisations/organisations_select_command.rb

Defined Under Namespace

Modules: Commands, Formatting, Model, Shells Classes: Client, Error

Constant Summary collapse

VERSION =
"0.9.2".freeze

Class Method Summary collapse

Class Method Details

.consoleObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/semaph.rb', line 12

def self.console
  organisations = load_organisations
  config = load_config

  if config
    console_with_config(organisations, config)
  elsif organisations.count == 1
    Shells::Organisation::OrganisationShell.new(organisations.first).push
  else
    Shells::Organisations::OrganisationsShell.new(organisations).push
  end
end

.console_with_config(organisations, config) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/semaph.rb', line 25

def self.console_with_config(organisations, config)
  organisation = organisations.find { |o| o["host"] == config[:host] }

  Shells::Project::ProjectShell.new(
    Model::Project.new(
      ::Semaph::Client.new(
        organisation["auth"]["token"],
        organisation["host"],
      ),
      config[:project],
    ),
  ).push
end

.load_configObject



50
51
52
53
54
# File 'lib/semaph.rb', line 50

def self.load_config
  return nil unless File.exist?(".semaph")

  YAML.load_file(".semaph")
end

.load_organisationsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/semaph.rb', line 39

def self.load_organisations
  yaml_path = File.join(File.expand_path("~"), ".sem.yaml")

  unless File.exist?(yaml_path)
    puts "Please install the sem tool and authenticate to semaphoreci.com"
    exit 1
  end

  YAML.load_file(yaml_path)["contexts"].values
end