sherpa-cli 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b55977c7c9ee8d75c0bc552ad8fe0b970da6fc9
4
- data.tar.gz: 40ae022379315df0c072a21d41e32163a126803d
3
+ metadata.gz: 1a628ccb93da38b954d4863665648af102ed56a9
4
+ data.tar.gz: ddabc92e0a16a5e96ee5517d9c3590a163b26e40
5
5
  SHA512:
6
- metadata.gz: 1d247289f0c2f3561f90e35597e71e91bdcf1899ff563495560fcf4d448a0d334edc2f7e63f814c3379e5c01597f1226d974269c0955a8858b11e3cbeec96248
7
- data.tar.gz: 7557034b4b9ee0ef5762b2619ca8a028ecb865b9948e3a5d39d90986e55eab72805ce110dcfc306d1d06a4c9f07597b9f2b93b12841a512d81d920cb3d4c63fc
6
+ metadata.gz: 67ce2af791ae7045cfcdfe10cfe434dceaff801738616a1f7af464560ac07038086382b4ee632c402f38438325fd8edf173e7a148c4e84418b755c933cbbd958
7
+ data.tar.gz: c70ae50a46f045534819045f8dbdb94b117895b787b4468b04b27fad513cb5daa6cf7220293a8c532e0812c9e6760d1242e602a1554c5de939e6318c2685746d
@@ -0,0 +1,3 @@
1
+ SHERPA_API_TOKEN="some-awesome-token"
2
+ SHERPA_API_URI="http://example.com"
3
+ SHERPA_CONFIG="spec/fixtures/.sherpa"
data/bin/sherpa CHANGED
@@ -6,4 +6,8 @@ Dotenv.load
6
6
 
7
7
  require "sherpa"
8
8
 
9
- Sherpa::CLI.run
9
+ unless Sherpa::Config.setup?
10
+ Sherpa::CLI::Config.run
11
+ end
12
+
13
+ Sherpa::CLI::Deploy.run
data/circle.yml CHANGED
@@ -1,5 +1,3 @@
1
1
  machine:
2
2
  ruby:
3
3
  version: 2.2.3
4
- environment:
5
- SHERPA_API_TOKEN: "test"
@@ -1,3 +1,4 @@
1
+ require "sherpa/config"
1
2
  require "sherpa/api_client"
2
3
  require "sherpa/cli"
3
4
  require "sherpa/git"
@@ -22,7 +22,7 @@ module Sherpa
22
22
  end
23
23
 
24
24
  def api_uri
25
- ENV.fetch("SHERPA_API_URL", "http://localhost:3000")
25
+ Sherpa::Config.api_uri
26
26
  end
27
27
 
28
28
  def default_headers
@@ -32,7 +32,7 @@ module Sherpa
32
32
  end
33
33
 
34
34
  def token
35
- ENV.fetch("SHERPA_API_TOKEN")
35
+ Sherpa::Config.api_token
36
36
  end
37
37
  end
38
38
 
@@ -1,51 +1,2 @@
1
- require "tty-prompt"
2
-
3
- module Sherpa
4
- class CLI
5
- def initialize
6
- @prompt = TTY::Prompt.new
7
- end
8
-
9
- def self.run
10
- new.run
11
- end
12
-
13
- def run
14
- self.trekker = trekker_prompt
15
- self.stage = prompt.select("Choose the stage!", stage_choices)
16
- self.branch = prompt.ask("What branch would you like to deploy?")
17
-
18
- deploy = Sherpa::Model::Deploy.new(
19
- trekker: trekker,
20
- stage: stage,
21
- branch: branch
22
- )
23
-
24
- deploy.kick_off!
25
-
26
- prompt.ok("Deploying - #{branch} for #{`whoami`.chomp} to #{trekker.name} - #{stage.name}")
27
-
28
- rescue FailedRequest => e
29
- prompt.error("API Request Failed :(")
30
- end
31
-
32
- private
33
-
34
- attr_reader :prompt
35
- attr_accessor :trekker, :stage, :branch
36
-
37
- def trekker_prompt
38
- TrekkerMenu.new(prompt).run
39
- end
40
-
41
- def stage_choices
42
- stages.each_with_object(Hash.new) do |stage, hash|
43
- hash.store(stage.label, stage)
44
- end
45
- end
46
-
47
- def stages
48
- @stages ||= Model::Stage.all(trekker_id: trekker.id).sort_by(&:name)
49
- end
50
- end
51
- end
1
+ require "sherpa/cli/config"
2
+ require "sherpa/cli/deploy"
@@ -0,0 +1,46 @@
1
+ require "yaml"
2
+
3
+ module Sherpa
4
+ module CLI
5
+ class Config
6
+ def initialize(prompt = TTY::Prompt.new)
7
+ @prompt = prompt
8
+ end
9
+
10
+ def self.run
11
+ new.run
12
+ end
13
+
14
+ def run
15
+ prompt.warn("You haven't setup your Sherpa config yet")
16
+ if setup_config?
17
+ setup_config_file
18
+ else
19
+ Kernel.exit
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :prompt
26
+
27
+ def setup_config?
28
+ prompt.yes?("Would you like to add your API key?", default: true, echo: false)
29
+ end
30
+
31
+ def setup_config_file
32
+ api_token = prompt.ask("API Key:")
33
+ config = {
34
+ api_token: api_token
35
+ }
36
+ write_config(config)
37
+ end
38
+
39
+ def write_config(config)
40
+ File.open("#{Dir.home}/.sherpa", "w+") do |file|
41
+ file.write(config.to_yaml)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ require "tty-prompt"
2
+
3
+ module Sherpa
4
+ module CLI
5
+ class Deploy
6
+ def initialize(prompt = TTY::Prompt.new)
7
+ @prompt = prompt
8
+ end
9
+
10
+ def self.run
11
+ new.run
12
+ end
13
+
14
+ def run
15
+ self.trekker = trekker_prompt
16
+ self.stage = prompt.select("Choose the stage!", stage_choices)
17
+ self.branch = prompt.ask("What branch would you like to deploy?")
18
+
19
+ deploy = Sherpa::Model::Deploy.new(
20
+ trekker: trekker,
21
+ stage: stage,
22
+ branch: branch
23
+ )
24
+
25
+ deploy.kick_off!
26
+
27
+ prompt.ok("Deploying - #{branch} for #{`whoami`.chomp} to #{trekker.name} - #{stage.name}")
28
+
29
+ rescue FailedRequest => e
30
+ prompt.error("API Request Failed :(")
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :prompt
36
+ attr_accessor :trekker, :stage, :branch
37
+
38
+ def trekker_prompt
39
+ TrekkerMenu.new(prompt).run
40
+ end
41
+
42
+ def stage_choices
43
+ stages.each_with_object(Hash.new) do |stage, hash|
44
+ hash.store(stage.label, stage)
45
+ end
46
+ end
47
+
48
+ def stages
49
+ @stages ||= Model::Stage.all(trekker_id: trekker.id).sort_by(&:name)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,37 @@
1
+ require "yaml"
2
+
3
+ module Sherpa
4
+ class Config
5
+ class << self
6
+ def setup?
7
+ !api_token.nil? && !api_uri.nil?
8
+ end
9
+
10
+ def api_token
11
+ config[:api_token]
12
+ end
13
+
14
+ def api_uri
15
+ ENV.fetch("SHERPA_API_URI", "http://sherpa.procoretech.com")
16
+ end
17
+
18
+ private
19
+
20
+ def config
21
+ @config ||= load_config
22
+ end
23
+
24
+ def load_config
25
+ if config_filepath.exist?
26
+ YAML.load_file(config_filepath)
27
+ else
28
+ Hash.new
29
+ end
30
+ end
31
+
32
+ def config_filepath
33
+ Pathname.new(ENV.fetch("SHERPA_CONFIG", "#{Dir.home}/.sherpa"))
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Sherpa
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sherpa-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Stock
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-19 00:00:00.000000000 Z
12
+ date: 2016-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dotenv
@@ -132,6 +132,7 @@ executables:
132
132
  extensions: []
133
133
  extra_rdoc_files: []
134
134
  files:
135
+ - ".env.test"
135
136
  - ".gitignore"
136
137
  - ".rspec"
137
138
  - CODE_OF_CONDUCT.md
@@ -144,6 +145,9 @@ files:
144
145
  - lib/sherpa.rb
145
146
  - lib/sherpa/api_client.rb
146
147
  - lib/sherpa/cli.rb
148
+ - lib/sherpa/cli/config.rb
149
+ - lib/sherpa/cli/deploy.rb
150
+ - lib/sherpa/config.rb
147
151
  - lib/sherpa/git.rb
148
152
  - lib/sherpa/git/repo.rb
149
153
  - lib/sherpa/model.rb
@@ -174,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
178
  version: '0'
175
179
  requirements: []
176
180
  rubyforge_project:
177
- rubygems_version: 2.4.5.1
181
+ rubygems_version: 2.5.1
178
182
  signing_key:
179
183
  specification_version: 4
180
184
  summary: A commandline client for Sherpa