dip 3.3.0 → 3.4.0

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
  SHA256:
3
- metadata.gz: 39afd269d744387e64e708e2c173c38ffe35605ae8aa4dffa9cd074142e0e9b1
4
- data.tar.gz: efb60031ad5646986fc5672b4579671d3225624b9bc38d1d26ba142a91b1b3ee
3
+ metadata.gz: f6b63ce6f69f4354b803173e399cb4f60578424af67138b7414374a5b72f459d
4
+ data.tar.gz: c1d60e9f4967bd4646b8c25eddf78f73c50573f2c8a0ecb8fd4124ec43356759
5
5
  SHA512:
6
- metadata.gz: c6d434a4250d5276e4ce91d3ed2393be9cbc93108a8fe32052f3cb6f54b2fd8fd740ee0652352fb32f26310ed30e559dbe17565eb2e16a195d7e6d7f226aaa58
7
- data.tar.gz: 5a5512fff638facb0f3bf185703a53df02fb009e1d3c29a80803724336607f8198891f4465f0b9b2cd730d6b866225118dd9d2efa59eacc77776038039be64c5
6
+ metadata.gz: '0315179aee1699c6e95ab45adb50d41a4ee672830c325f82f5e1e5fb99dde1080e89f728507b81b6b92d3a24db0161e290f85c9e32768aa0ef15b1bf7ef9c943'
7
+ data.tar.gz: dde2a5dc5f9c9ba5560a596ab0c3e4a8ce7793f66968bf618354063dedeae96ef988ed544b817ffd2744bdcd7aaa4d58346b2e035fbac4f7812cd28aad24e2af
data/README.md CHANGED
@@ -121,25 +121,31 @@ dip compose up -d redis
121
121
 
122
122
  ### Integration with shell
123
123
 
124
- Dip can be injected into your current shell. For now, it supported ZSH only.
124
+ Dip can be injected into current shell. For now, it supported ZSH only.
125
125
 
126
126
  Inject Dip rc file (by default it saved to ~/.dip_shell_rc) into ZSH:
127
127
 
128
128
  ```sh
129
- source $(dip console)
129
+ dip console | source /dev/stdin
130
130
  ```
131
131
 
132
- After that you can type commands without `dip` prefix. For example:
132
+ After that we can type commands without `dip` prefix. For example:
133
133
 
134
134
  ```sh
135
- d> <run-command> *any-args
136
- d> compose *any-compose-arg
137
- d> up <service>
138
- d> down
139
- d> provision
135
+ <run-command> *any-args
136
+ compose *any-compose-arg
137
+ up <service>
138
+ down
139
+ provision
140
140
  ```
141
141
 
142
- When you change the current directory, all shell aliases will be automatically removed. But when you will enter back to a directory with a dip.yml file, then shell aliases will be renewed.
142
+ When we change the current directory, all shell aliases will be automatically removed. But when we will enter back to a directory with a dip.yml file, then shell aliases will be renewed.
143
+
144
+ Also, in shell mode Dip is trying to determine passed manually environment variables. For example:
145
+
146
+ ```sh
147
+ VERSION=20180515103400 rails db:migrate:down
148
+ ```
143
149
 
144
150
  ### dip ssh
145
151
 
data/exe/dip CHANGED
@@ -6,6 +6,7 @@ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
6
 
7
7
  require 'dip'
8
8
  require 'dip/cli'
9
+ require 'dip/run_vars'
9
10
 
10
11
  begin
11
12
  require 'pry-byebug' if Dip.debug?
@@ -19,23 +20,7 @@ Signal.trap('INT') do
19
20
  end
20
21
 
21
22
  begin
22
- run_vars = []
23
-
24
- ARGV.each do |arg|
25
- if !run_vars.frozen? && arg.include?("=")
26
- key, val = arg.split("=", 2)
27
- run_vars << "#{'--x-dip-run-vars=' if run_vars.empty?}#{key}:#{val}"
28
- else
29
- run_vars.freeze
30
- end
31
- end
32
-
33
- unless run_vars.empty?
34
- ARGV.shift(run_vars.size)
35
- ARGV.push(*run_vars)
36
- end
37
-
38
- Dip::CLI.start
23
+ Dip::CLI.start(Dip::RunVars.call(ARGV, ENV))
39
24
  rescue Dip::Error => err
40
25
  puts "ERROR: #{err.message}"
41
26
  exit 1
@@ -7,22 +7,16 @@ module Dip
7
7
  module Console
8
8
  class Start < Dip::Command
9
9
  def execute
10
- File.write(rc_file, script_content)
11
-
12
- puts rc_file
10
+ puts script
13
11
  end
14
12
 
15
13
  private
16
14
 
17
- def rc_file
18
- @rc_file ||= "#{Dir.home}/.dip_shell_rc"
19
- end
20
-
21
- def script_content
15
+ def script
22
16
  <<-SH.gsub(/^[ ]{12}/, '')
23
17
  if [ "$DIP_SHELL" != "1" ]; then
24
- export PS1="${PS1}d> "
25
- export DIP_SHELL=1
18
+ export DIP_SHELL=zsh
19
+ export DIP_EARLY_ENVS=#{ENV.keys.join(',')}
26
20
  fi
27
21
 
28
22
  function _dip_remove_aliases() {
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dip
4
+ class RunVars
5
+ attr_reader :argv, :env, :early_envs, :env_vars, :result_argv
6
+
7
+ def self.call(*args)
8
+ new(*args).call
9
+ end
10
+
11
+ def initialize(argv, env = ENV)
12
+ @argv = argv
13
+ @env = env
14
+ @env_vars = {}
15
+ @result_argv = []
16
+ end
17
+
18
+ def call
19
+ extract_new_env_vars
20
+ extract_passed_env_vars
21
+
22
+ result_argv.push(*argv_env_vars) unless env_vars.empty?
23
+
24
+ result_argv
25
+ end
26
+
27
+ private
28
+
29
+ def extract_new_env_vars
30
+ early_envs = env['DIP_EARLY_ENVS'].to_s
31
+ return if early_envs.empty?
32
+
33
+ (env.keys - early_envs.split(',')).each do |key|
34
+ next if key.start_with?("DIP_")
35
+
36
+ env_vars[key] = env[key]
37
+ end
38
+ end
39
+
40
+ def extract_passed_env_vars
41
+ stop_parse = false
42
+
43
+ argv.each do |arg|
44
+ if !stop_parse && arg.include?("=")
45
+ key, val = arg.split("=", 2)
46
+ env_vars[key] = val
47
+ else
48
+ result_argv << arg
49
+ stop_parse ||= true
50
+ end
51
+ end
52
+ end
53
+
54
+ def argv_env_vars
55
+ result = env_vars.map { |key, val| "#{key}:#{val}" }
56
+ result[0] = "--x-dip-run-vars=#{result[0]}"
57
+
58
+ result
59
+ end
60
+ end
61
+ end
data/lib/dip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dip
4
- VERSION = "3.3.0"
4
+ VERSION = "3.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bibendi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2018-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -150,6 +150,7 @@ files:
150
150
  - lib/dip/commands/ssh.rb
151
151
  - lib/dip/config.rb
152
152
  - lib/dip/environment.rb
153
+ - lib/dip/run_vars.rb
153
154
  - lib/dip/version.rb
154
155
  homepage: https://github.com/bibendi/dip
155
156
  licenses: