gpgenv 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ecbe2313308b638a10d233136b3a48289e554cc
4
- data.tar.gz: 7bcf49271836774facf4fb957a07bfb6d69397ee
3
+ metadata.gz: f53c68a5984ba9f9b5e583242c21319cd8b378fb
4
+ data.tar.gz: 117960f3ebbccd6744e3afabb7dae6a519e40638
5
5
  SHA512:
6
- metadata.gz: a32b7b1ee9943987ec23dc2085c7ec84db2aeff0ece43c1fa5566dad22d1ff4e1eff408ee1226c117d4c5aaa232582a83d26aad3aaec9f53608b7bab9af3a5fc
7
- data.tar.gz: d5218f52b6e4832ec5d1337e243403af82caf3c825e4801930a54d33ca433b3362ece09f54caf35b76ff09a70f17ff03bedc8c2c6049bb05c4c45ebb53421160
6
+ metadata.gz: de27f8b06e937383264654be602747a3281aba890bb65c3a775b4de4ae6605ee929659868c19230e7c504a36aba8ee844c884f4f876d9fed46881040def87754
7
+ data.tar.gz: 4ca93d6e4ffd4a1134708107b79f586797baa28ebe15517eae860d30c2c71c24eab8d5d7d5b5b9792b9120438d2b172864a32f1e8b55930b0c6ed8d6f35fb2ac
@@ -1,14 +1,30 @@
1
1
  require 'clamp'
2
2
  require 'gpgenv/base_command'
3
+ require 'gpgenv/profile'
3
4
  require 'gpgenv'
4
5
 
5
6
  class Gpgenv
6
7
  class ExecCommand < Gpgenv::BaseCommand
7
8
 
9
+ option ['-p', '--profile'], "PROFILE", "Profile to use, from ~/.gpgenvrc", attribute_name: :profile
8
10
  parameter "ARGUMENTS ...", "arguments", :attribute_name => :args
9
11
 
10
12
  def execute
11
- gpgenv.exec_command args[0..-1].join(' ')
13
+ executor.exec_command args[0..-1].join(' ')
14
+ end
15
+
16
+ def executor
17
+ # If GPGENV_PRPOFILE is set or a profile is passed on the CLI, use the given profile
18
+ # Otherwise use a standard Gpgenv object to execute.
19
+ if prof
20
+ Profile.new("#{ENV['HOME']}/.gpgenvrc", prof)
21
+ else
22
+ gpgenv
23
+ end
24
+ end
25
+
26
+ def prof
27
+ profile || ENV['GPGENV_PROFILE']
12
28
  end
13
29
 
14
30
  end
@@ -0,0 +1,40 @@
1
+ require 'yaml'
2
+
3
+ class Gpgenv
4
+ class Profile
5
+ attr_reader :file, :name
6
+ def initialize(file, name)
7
+ @file = file
8
+ @name = name
9
+ end
10
+
11
+ def exec_command(cmd)
12
+ exec(read_files, cmd)
13
+ end
14
+
15
+ private
16
+
17
+ def read_files
18
+ hash = {}
19
+ gpgenvs.each do |gpgenv|
20
+ hash.merge!(gpgenv.read_files)
21
+ end
22
+ hash
23
+ end
24
+
25
+ def gpgenvs
26
+ fail(".gpgenvrc file does not exist") unless File.exist?(file)
27
+ yaml = YAML.load(File.read(file))
28
+ fail("Invalid .gpgenvrc file") unless yaml.is_a?(Hash)
29
+ value = yaml[name]
30
+
31
+ fail("No such profile: #{name} in .gpgenvrc") unless value
32
+ fail("Invalid .gpgenvrc file") if !value.is_a?(Array)
33
+
34
+ value.map{ |dir| Gpgenv.new(dir: dir) }
35
+ rescue Psych::SyntaxError => e
36
+ fail("Malformed .gpgenvrc file: #{e.message}")
37
+ end
38
+
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  class Gpgenv
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpgenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Shea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-14 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -144,6 +144,7 @@ files:
144
144
  - lib/gpgenv/export_command.rb
145
145
  - lib/gpgenv/gpgenv_command.rb
146
146
  - lib/gpgenv/import_command.rb
147
+ - lib/gpgenv/profile.rb
147
148
  - lib/gpgenv/set_command.rb
148
149
  - lib/gpgenv/shell_command.rb
149
150
  - lib/gpgenv/version.rb