wslc-wip 0.1.2 → 0.2.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
  SHA256:
3
- metadata.gz: c029c0b9ac521978ed14280f2a1729c7660072ab9167a14cc64d9c009b3e0574
4
- data.tar.gz: 338e9ceacddd365347fad3e205ba2fd2d33925b53bf923d88f0d044df3f82aea
3
+ metadata.gz: bc4331f98464658b13ec0ac51737183931ce6ed5320d15cf64b2313b50aa7999
4
+ data.tar.gz: 3d9cac0a97bd2abb2a0c30f5c5bc5a8c626320d900f4ac7cd46aca682368b56c
5
5
  SHA512:
6
- metadata.gz: 2c2a9d8f03bb83e506990e5c9c621f782d99681dc292277f50a4e6cde0d1f98cf1a853641abd328ba4431fe892d05a986e00d220aab51d652b66dcd6c2d68246
7
- data.tar.gz: afa6e3ffc70cc339d6c45c72a78ef0006b39cf7573252ed997029a823680cb63c1290fc7fdbf11f289393c903bde4db7686a72c1637edf3eb0d04a6a25165c08
6
+ metadata.gz: 8568791708d1e6b87b85c209568d47580daf0008253dc41b824c9a4377d35f08c2b1005a6082b7ab3eefeaf2cc7ead6ce8357a31047bc17dda0b9f6afcc70266
7
+ data.tar.gz: 827d83e3244bc9269b12139f5e4554f7b0e2137b1a2a54ac3258799a2c531d355e9a3405ec4bbffff1b134b7b39cbcde0a13a1ba06df35f93cc995b45e4637b7
data/README.md CHANGED
@@ -82,6 +82,8 @@ commands:
82
82
  | `wip doctor` | WSL2、相互運用、WSLC、設定、アーキテクチャ、Git を診断 |
83
83
  | `wip config` | デフォルト適用済み設定(秘密値をマスク) |
84
84
  | `wip build -- --no-cache` | build 定義でイメージをビルド |
85
+ | `wip up [-d]` | `defaults.container` を起動(無ければ作成)。`-d` でバックグラウンド実行 |
86
+ | `wip down` | `defaults.container` を停止・削除 |
85
87
  | `wip exec [--no-interactive] COMMAND...` | 既存コンテナ内で実行 |
86
88
  | `wip run [--no-interactive] COMMAND...` | `--rm` の新規コンテナで実行 |
87
89
  | `wip shell` | 定義済み shell、または `bash`、`sh` の順に起動 |
data/lib/wip/cli.rb CHANGED
@@ -9,6 +9,20 @@ module Wip
9
9
  class_option :config, type: :string, desc: 'Path to wip.yml'
10
10
  default_task :dispatch
11
11
 
12
+ def self.exit_on_failure? = true
13
+
14
+ # Thor only falls back to the default task when no command name is given at
15
+ # all; an unrecognized first argument (e.g. a custom wip.yml command name)
16
+ # would otherwise raise "Could not find command". Route those to `dispatch`.
17
+ def self.dispatch(meth, given_args, given_opts, config)
18
+ name = given_args.first
19
+ if meth.nil? && name && !name.to_s.start_with?('-') && find_command_possibilities(name).empty?
20
+ return super('dispatch', given_args, given_opts, config)
21
+ end
22
+
23
+ super
24
+ end
25
+
12
26
  desc 'version', 'Show wip and WSLC versions'
13
27
  def version
14
28
  puts "wip #{VERSION}"
@@ -37,6 +51,19 @@ module Wip
37
51
  execute(builder.build(settings: load_config.command('build') || {}, extra: extra))
38
52
  end
39
53
 
54
+ desc 'up', 'Start the configured container, creating it if necessary'
55
+ option :detach, type: :boolean, default: false, aliases: '-d'
56
+ def up
57
+ code = execute(builder.start(detach: options[:detach]), exit_on_failure: false)
58
+ execute(builder.up(detach: options[:detach])) if code != 0
59
+ end
60
+
61
+ desc 'down', 'Stop and remove the configured container'
62
+ def down
63
+ execute(builder.down, exit_on_failure: false)
64
+ execute(builder.remove, exit_on_failure: false)
65
+ end
66
+
40
67
  desc 'exec COMMAND...', 'Execute a command in the running container'
41
68
  option :interactive, type: :boolean, default: true
42
69
  def exec(*command)
@@ -55,7 +82,8 @@ module Wip
55
82
  configured = load_config.command('shell')
56
83
  return execute(builder.custom('shell', [])) if configured
57
84
 
58
- code = execute(builder.exec(['bash'], settings: { 'interactive' => true }, interactive: true))
85
+ code = execute(builder.exec(['bash'], settings: { 'interactive' => true }, interactive: true),
86
+ exit_on_failure: false)
59
87
  execute(builder.exec(['sh'], settings: { 'interactive' => true }, interactive: true)) if code != 0
60
88
  end
61
89
  map 'shell' => :shell_command
@@ -74,9 +102,9 @@ module Wip
74
102
  def resolver = CommandResolver.new
75
103
  def builder = CommandBuilder.new(wslc: resolver.resolve(load_config.wslc_command), config: load_config)
76
104
 
77
- def execute(command)
105
+ def execute(command, exit_on_failure: true)
78
106
  code = CommandRunner.new.run(command)
79
- exit(code) unless code.zero?
107
+ exit(code) if exit_on_failure && !code.zero?
80
108
  code
81
109
  end
82
110
  end
@@ -26,6 +26,28 @@ module Wip
26
26
  command.concat(options(values)).push(required(values, 'image')).concat(arguments)
27
27
  end
28
28
 
29
+ def up(detach: false)
30
+ values = @config.defaults
31
+ command = [@wslc, 'run', '--name', required(values, 'container')]
32
+ command << '-d' if detach
33
+ command << '-it' if !detach && tty?(true)
34
+ command.concat(options(values)).push(required(values, 'image'))
35
+ end
36
+
37
+ def start(detach: false)
38
+ command = [@wslc, 'start', required(@config.defaults, 'container')]
39
+ command.push('-a', '-i') unless detach
40
+ command
41
+ end
42
+
43
+ def down
44
+ [@wslc, 'stop', required(@config.defaults, 'container')]
45
+ end
46
+
47
+ def remove
48
+ [@wslc, 'remove', '-f', required(@config.defaults, 'container')]
49
+ end
50
+
29
51
  def build(settings:, extra: [])
30
52
  values = @config.defaults.merge(settings)
31
53
  context = values['context'] || '.'
data/lib/wip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wip
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wslc-wip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wip contributors