mux_tf 0.1.2 → 0.2.4

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: 72d1bbf43fcbb38f0d1a8c4bba72321f582a4ff10ce75a49c87cef89e21647ac
4
- data.tar.gz: 2be9f70c1ce5a58df894866e02cd8efcfa04aa500ac394218368ef2bb88ee6fc
3
+ metadata.gz: 3748671ba7cadd0a528d33b4066e929df30817f1741cedd4126088e3148a1edb
4
+ data.tar.gz: 475c07f7d293f759082c4138d7bccb6cc2c04493fae45b2751225cdc98b6775e
5
5
  SHA512:
6
- metadata.gz: e64d359f26aafe4d2fd88f00d6294132ee1ed917a5bd02eda45500d55700327e7c70fad0a053b2007db2e350c822509288e1900ad30601571bce097795d70ae4
7
- data.tar.gz: 1c3b1ac826bace9b8191ce9ae55b392956ddb24e3d89d4aef86080799f408fd545d9efe4254e309a48515a9896e9f757ac20dc7938f42ee12d9f09a3a1a4cc8e
6
+ metadata.gz: d87307602bb62b5be1e8686c7ea3a8315ba10ffd972bc20a930296281de520b025b96b3312af2bebb6317944544b0bb3caea35aba702c4dddfe4fa4a7ca8534d
7
+ data.tar.gz: 9371bb009d008ec46cf2ceb0c2542dca1ce424b5ddac7555d696ea72e12a4e0a4c3c3614a8a9e8b2388c6552a98df4f2d6439ef39262f3f640a6098bfe9bdf5c
data/README.md CHANGED
@@ -31,7 +31,17 @@ ROOT/
31
31
 
32
32
  ## Development
33
33
 
34
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+ To install this gem onto your local machine, run `bundle exec rake install`.
35
+
36
+ ## Releasing
37
+
38
+ To release a new version, first bump the version number by running:
39
+
40
+ ```shell
41
+ gem bump -v major|minor|patch
42
+ ```
43
+
44
+ And then run `rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
45
 
36
46
  ## Contributing
37
47
 
@@ -23,6 +23,8 @@ require_relative './mux_tf/cli'
23
23
  require_relative './mux_tf/tmux'
24
24
  require_relative './mux_tf/terraform_helpers'
25
25
  require_relative './mux_tf/plan_formatter'
26
+ require_relative './mux_tf/version_check'
27
+ require_relative './mux_tf/yaml_cache'
26
28
 
27
29
  module MuxTf
28
30
  end
@@ -12,6 +12,8 @@ module MuxTf
12
12
 
13
13
  class << self
14
14
  def run(args)
15
+ version_check
16
+
15
17
  if args[0] == 'cli'
16
18
  cmd_loop
17
19
  return
@@ -57,6 +59,17 @@ module MuxTf
57
59
 
58
60
  private
59
61
 
62
+ def version_check
63
+ if VersionCheck.has_updates?
64
+ log Paint["="*80, :yellow]
65
+ log "New version of #{Paint["mux_tf", :cyan]} is available!"
66
+ log "You are currently on version: #{Paint[VersionCheck.current_gem_version, :yellow]}"
67
+ log "Latest version found is: #{Paint[VersionCheck.latest_gem_version, :green]}"
68
+ log "Run `#{Paint["gem install mux_tf", :green]}` to update!"
69
+ log Paint["="*80, :yellow]
70
+ end
71
+ end
72
+
60
73
  def run_validate
61
74
  remedies = PlanFormatter.process_validation(validate)
62
75
  process_remedies(remedies)
@@ -225,7 +238,7 @@ module MuxTf
225
238
 
226
239
  def interactive_cmd
227
240
  define_cmd('interactive', summary: 'Apply interactively') do |_opts, _args, _cmd|
228
- status = run_shell(['tf-plan-summary', PLAN_FILENAME, '-i'], return_status: true)
241
+ status = run_shell([tf_plan_summrary_cmd, PLAN_FILENAME, '-i'], return_status: true)
229
242
  if status != 0
230
243
  log 'Interactive Apply Failed!'
231
244
  else
@@ -46,10 +46,12 @@ module MuxTf
46
46
 
47
47
  Tmux.set 'mouse', 'on'
48
48
 
49
+ window_id = Tmux.list_windows.first[:id]
50
+
49
51
  unless tasks.empty?
50
52
  tasks.each do |task|
51
53
  log "launching task: #{task[:name]} ...", depth: 2
52
- Tmux.split_window :horizontal, "#{project}:1", cmd: task[:cmd], cwd: task[:cwd]
54
+ Tmux.split_window :horizontal, "#{project}:#{window_id}", cmd: task[:cmd], cwd: task[:cwd]
53
55
  Tmux.select_pane task[:name]
54
56
  Tmux.tile!
55
57
  task[:commands]&.each do |cmd|
@@ -28,7 +28,7 @@ module MuxTf
28
28
  parser.state(:error_lock_info, /Lock Info/, [:error])
29
29
  parser.state(:error, /^$/, [:error_lock_info])
30
30
 
31
- parser.state(:plan_error, /^Error: /, [:refreshing])
31
+ parser.state(:plan_error, /^Error: /, %i[refreshing refresh_done])
32
32
 
33
33
  status = tf_plan(out: filename, detailed_exitcode: true, compact_warnings: true) do |raw_line|
34
34
  plan_output << raw_line
@@ -21,6 +21,13 @@ module MuxTf
21
21
  panes.find { |pane| pane[:name] == name }
22
22
  end
23
23
 
24
+ def list_windows
25
+ `tmux list-windows -F "\#{window_id},\#{window_index},\#{window_name}"`.strip.split("\n").map do |row|
26
+ x = row.split(',')
27
+ { id: x[0], index: x[1], name: x[2] }
28
+ end
29
+ end
30
+
24
31
  def new_session(name)
25
32
  tmux %(new-session -s #{name.inspect} -d)
26
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuxTf
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.4'
5
5
  end
@@ -0,0 +1,28 @@
1
+ module MuxTf
2
+ module VersionCheck
3
+ def has_updates?
4
+ current_gem_version < latest_gem_version
5
+ end
6
+
7
+ def latest_gem_version
8
+ value = cache.fetch("latest_gem_version") do
9
+ fetcher = Gem::SpecFetcher.fetcher
10
+ dependency = Gem::Dependency.new "mux_tf"
11
+ remotes, = fetcher.search_for_dependency dependency
12
+ remotes.map(&:first).map(&:version).sort.last.to_s
13
+ end
14
+
15
+ Gem::Version.new(value)
16
+ end
17
+
18
+ def current_gem_version
19
+ Gem::Version.new(MuxTf::VERSION)
20
+ end
21
+
22
+ def cache
23
+ @cache ||= YamlCache.new(File.expand_path("~/.mux_tf.yaml"), default_ttl: 1.hour)
24
+ end
25
+
26
+ extend self
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'yaml/store'
2
+
3
+ module MuxTf
4
+ class YamlCache
5
+ def initialize(path, default_ttl:)
6
+ @default_ttl = default_ttl
7
+ @store = YAML::Store.new path
8
+ end
9
+
10
+ def set(key, value, ttl: @default_ttl)
11
+ @store.transaction do
12
+ @store[key] = {
13
+ expires_at: Time.now + ttl,
14
+ value: value
15
+ }
16
+ end
17
+ end
18
+
19
+ def fetch(key, ttl: @default_ttl)
20
+ info = nil
21
+ @store.transaction(true) do
22
+ info = @store[key]
23
+ end
24
+
25
+ if info.nil? || info[:expires_at] < Time.now
26
+ if block_given?
27
+ value = yield
28
+ set(key, value, ttl: ttl)
29
+ return value
30
+ else
31
+ raise KeyError, info.nil? ? "no value at key: #{key}" : "value expired at key: #{key}"
32
+ end
33
+ end
34
+
35
+ info[:value]
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mux_tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Banasik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-25 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -149,6 +149,8 @@ files:
149
149
  - lib/mux_tf/terraform_helpers.rb
150
150
  - lib/mux_tf/tmux.rb
151
151
  - lib/mux_tf/version.rb
152
+ - lib/mux_tf/version_check.rb
153
+ - lib/mux_tf/yaml_cache.rb
152
154
  - mux_tf.gemspec
153
155
  homepage: https://github.com/piotrb/mux_tf
154
156
  licenses: