brut 0.21.0.pre.1 → 0.21.0.pre.3
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 +4 -4
- data/lib/brut/cli/apps/db.rb +22 -10
- data/lib/brut/cli/apps/deploy.rb +12 -16
- data/lib/brut/cli/apps/new/app.rb +3 -0
- data/lib/brut/cli/apps/new/segments/docker_deploy.rb +1 -2
- data/lib/brut/cli/apps/test.rb +22 -14
- data/lib/brut/cli/commands/base_command.rb +29 -11
- data/lib/brut/cli/commands/compound_command.rb +19 -3
- data/lib/brut/cli/commands/help.rb +1 -0
- data/lib/brut/cli/commands/help_in_markdown.rb +1 -0
- data/lib/brut/cli/parsed_command_line.rb +1 -12
- data/lib/brut/cli/runner.rb +11 -14
- data/lib/brut/spec_support/cli_command_support.rb +12 -5
- data/lib/brut/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7d83ff98517963f25fc7bda801f0525203a946b11a69c7c95ea18a7790d74a8
|
|
4
|
+
data.tar.gz: b11d1fd32f24dd4a5b654541a1c4f26f4039d8b2a1f2dc804eb1dcf255ef4df1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91af7b2b9ee3bf7b5aff57c0f656c050b4a89d8aebd1e38e9413aadd8d1d6378454a295c93134e8b5b24d9277ecfdd8c6ae296d5f08fceb7993b22191324972b
|
|
7
|
+
data.tar.gz: e2b3a79d3b2de5963bdf2fb9e8a6f6ec50afc105d79f0ba24669bd9174aa9aad1ec6579d940e4d4f2bd39f6d292f1f00ad760857cb9ca1ef323caac2d7ddf7b6
|
data/lib/brut/cli/apps/db.rb
CHANGED
|
@@ -247,6 +247,14 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
|
|
|
247
247
|
execution_context.logger.without_stderr,
|
|
248
248
|
self
|
|
249
249
|
)
|
|
250
|
+
database_description = if Brut.container.project_env.production?
|
|
251
|
+
"production database"
|
|
252
|
+
else
|
|
253
|
+
Brut.container.database_url
|
|
254
|
+
end
|
|
255
|
+
puts theme.header.render("🏗 Applying migrations to #{database_description}")
|
|
256
|
+
|
|
257
|
+
|
|
250
258
|
Sequel::Migrator.run(Brut.container.sequel_db_handle,migrations_dir)
|
|
251
259
|
puts theme.success.render("✅ All migrations have been applied")
|
|
252
260
|
0
|
|
@@ -263,12 +271,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
|
|
|
263
271
|
].join(" ")
|
|
264
272
|
1
|
|
265
273
|
rescue Sequel::DatabaseError => ex
|
|
266
|
-
|
|
267
|
-
# # ignoring - we are running migrations which will address this
|
|
268
|
-
# 0
|
|
269
|
-
#else
|
|
270
|
-
raise ex
|
|
271
|
-
#end
|
|
274
|
+
raise ex
|
|
272
275
|
end
|
|
273
276
|
end
|
|
274
277
|
|
|
@@ -276,15 +279,24 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
|
|
|
276
279
|
def description = "Drop, re-create, and run migrations, effecitvely rebuilding the entire database"
|
|
277
280
|
def default_rack_env = "development"
|
|
278
281
|
def bootstrap? = false
|
|
279
|
-
def
|
|
280
|
-
|
|
282
|
+
def opts = [
|
|
283
|
+
[ "--seed", "Load seed data after rebuild" ]
|
|
284
|
+
]
|
|
285
|
+
def commands(execution_context)
|
|
286
|
+
default_commands = [
|
|
281
287
|
Drop.new,
|
|
282
288
|
Create.new,
|
|
283
289
|
Migrate.new,
|
|
284
|
-
]
|
|
290
|
+
]
|
|
291
|
+
if execution_context.options.seed?
|
|
292
|
+
default_commands + [ Seed.new ]
|
|
293
|
+
else
|
|
294
|
+
default_commands
|
|
295
|
+
end
|
|
285
296
|
end
|
|
286
297
|
end
|
|
287
298
|
|
|
299
|
+
# XXX
|
|
288
300
|
|
|
289
301
|
class Seed < Brut::CLI::Commands::BaseCommand
|
|
290
302
|
def description = "Load seed data into the database"
|
|
@@ -310,7 +322,7 @@ class Brut::CLI::Apps::DB < Brut::CLI::Commands::BaseCommand
|
|
|
310
322
|
puts theme.exception.render(" #{ex}".strip)
|
|
311
323
|
puts [
|
|
312
324
|
theme.error.render("You can re-load it using"),
|
|
313
|
-
theme.code.render("brut db rebuild
|
|
325
|
+
theme.code.render("brut db rebuild --seed"),
|
|
314
326
|
].join(" ")
|
|
315
327
|
1
|
|
316
328
|
end
|
data/lib/brut/cli/apps/deploy.rb
CHANGED
|
@@ -9,11 +9,8 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
9
9
|
autoload :GitChecks, "brut/cli/apps/deploy/git_checks"
|
|
10
10
|
|
|
11
11
|
def name = "deploy"
|
|
12
|
-
|
|
13
12
|
def description = "Deploy your Brut-powered app to production"
|
|
14
13
|
|
|
15
|
-
def default_rack_env = nil
|
|
16
|
-
|
|
17
14
|
class Docker < Brut::CLI::Commands::BaseCommand
|
|
18
15
|
def description = "Build one docker image to use for all commands in production"
|
|
19
16
|
def opts = [
|
|
@@ -47,10 +44,7 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
47
44
|
end
|
|
48
45
|
version = ""
|
|
49
46
|
git_guess = %{git rev-parse HEAD}
|
|
50
|
-
|
|
51
|
-
version << output
|
|
52
|
-
end
|
|
53
|
-
version = version.strip.chomp
|
|
47
|
+
version = capture!(git_guess).strip.chomp
|
|
54
48
|
if version == ""
|
|
55
49
|
fatal "Attempt to use git via command '#{git_guess}' to figure out the version failed"
|
|
56
50
|
return 1
|
|
@@ -66,12 +60,12 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
66
60
|
dockerfile = Brut.container.project_root / "deploy" / "Dockerfile"
|
|
67
61
|
FileUtils.chdir Brut.container.project_root do
|
|
68
62
|
command = %{docker build --build-arg app_git_sha1=#{version} --file #{dockerfile} --platform #{config.platform} --tag #{image_name} . 2>&1}
|
|
69
|
-
system!(command)
|
|
63
|
+
system!(command, output: :stream)
|
|
70
64
|
end
|
|
71
65
|
if options.build_only?
|
|
72
66
|
puts "Not pushing image"
|
|
73
67
|
else
|
|
74
|
-
system!("docker image push #{image_name}")
|
|
68
|
+
system!("docker image push #{image_name}", output: :stream)
|
|
75
69
|
end
|
|
76
70
|
|
|
77
71
|
0
|
|
@@ -99,6 +93,7 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
99
93
|
end
|
|
100
94
|
end
|
|
101
95
|
end
|
|
96
|
+
def default_rack_env = "development"
|
|
102
97
|
def description = "Deploy to Heroku using container-based deployment"
|
|
103
98
|
def opts = [
|
|
104
99
|
[ "--build-only", "Only generate Dockerfiles and build images, do not deploy" ],
|
|
@@ -139,10 +134,7 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
139
134
|
config = AppDeployConfig.new
|
|
140
135
|
version = ""
|
|
141
136
|
git_guess = %{git rev-parse HEAD}
|
|
142
|
-
|
|
143
|
-
version << output
|
|
144
|
-
end
|
|
145
|
-
version = version.strip.chomp
|
|
137
|
+
version = capture!(git_guess).strip.chomp
|
|
146
138
|
if version == ""
|
|
147
139
|
fatal "Attempt to use git via command '#{git_guess}' to figure out the version failed"
|
|
148
140
|
return 1
|
|
@@ -161,14 +153,14 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
161
153
|
"--push"
|
|
162
154
|
end
|
|
163
155
|
command = %{docker buildx build --provenance=false --build-arg app_git_sha1=#{version} --file #{process_dockerfile_path} --platform #{config.platform} #{push_or_load} --tag #{image_name} . 2>&1}
|
|
164
|
-
system!(command)
|
|
156
|
+
system!(command, output: :stream)
|
|
165
157
|
names << process_description.name
|
|
166
158
|
end
|
|
167
159
|
deploy_command = "heroku container:release #{names.sort.join(' ')} -a #{Brut.container.app_id}"
|
|
168
160
|
if options.build_only?
|
|
169
161
|
puts "Not deploying"
|
|
170
162
|
else
|
|
171
|
-
system!(deploy_command)
|
|
163
|
+
system!(deploy_command, output: :stream)
|
|
172
164
|
end
|
|
173
165
|
|
|
174
166
|
0
|
|
@@ -178,9 +170,12 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
178
170
|
end
|
|
179
171
|
end
|
|
180
172
|
end
|
|
181
|
-
|
|
173
|
+
class DockerCompose < Brut::CLI::Commands::BaseCommand
|
|
174
|
+
def default_rack_env = "development"
|
|
175
|
+
def description = "Manage a docker-compose.yml file to be consistent with your deploy config"
|
|
182
176
|
class Check < Brut::CLI::Commands::BaseCommand
|
|
183
177
|
def description = "Check if the existing docker-compose.yml is consistent with the deploy config"
|
|
178
|
+
def default_rack_env = "development"
|
|
184
179
|
def run
|
|
185
180
|
docker_compose_path = Brut.container.project_root / "deploy" / "docker-compose.yml"
|
|
186
181
|
if !docker_compose_path.exist?
|
|
@@ -265,6 +260,7 @@ class Brut::CLI::Apps::Deploy < Brut::CLI::Commands::BaseCommand
|
|
|
265
260
|
end
|
|
266
261
|
class Generate < Brut::CLI::Commands::BaseCommand
|
|
267
262
|
def description = "Generate or update the existing docker-compose.yml based on current deploy config"
|
|
263
|
+
def default_rack_env = "development"
|
|
268
264
|
def run
|
|
269
265
|
docker_compose_path = Brut.container.project_root / "deploy" / "docker-compose.yml"
|
|
270
266
|
deploy_config_path = Brut.container.project_root / "deploy" / "deploy_config.rb"
|
|
@@ -84,6 +84,8 @@ class Brut::CLI::Apps::New::App < Brut::CLI::Commands::BaseCommand
|
|
|
84
84
|
],
|
|
85
85
|
]
|
|
86
86
|
|
|
87
|
+
def default_rack_env = nil
|
|
88
|
+
|
|
87
89
|
def run
|
|
88
90
|
|
|
89
91
|
app_name = argv[0]
|
|
@@ -262,6 +264,7 @@ class Brut::CLI::Apps::New::App < Brut::CLI::Commands::BaseCommand
|
|
|
262
264
|
|
|
263
265
|
class Segment < Brut::CLI::Commands::BaseCommand
|
|
264
266
|
def description = "Add a segement to your app to provide additional pre-configured functionality"
|
|
267
|
+
def default_rack_env = nil
|
|
265
268
|
|
|
266
269
|
def args_description = "segment_name"
|
|
267
270
|
|
|
@@ -8,8 +8,7 @@ class Brut::CLI::Apps::New::Segments::DockerDeploy < Brut::CLI::Apps::New::Base
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def add!
|
|
11
|
-
operations = copy_files(@templates_dir, @project_root)
|
|
12
|
-
other_operations
|
|
11
|
+
operations = copy_files(@templates_dir, @project_root)
|
|
13
12
|
|
|
14
13
|
operations.each do |operation|
|
|
15
14
|
operation.call
|
data/lib/brut/cli/apps/test.rb
CHANGED
|
@@ -50,20 +50,26 @@ Runs all non end-to-end tests for the app, or runs a subset of non-end-to-end te
|
|
|
50
50
|
def rebuild_after_by_default? = false
|
|
51
51
|
|
|
52
52
|
def run
|
|
53
|
-
|
|
54
|
-
puts "Rebuilding test database schema"
|
|
55
|
-
Bundler.with_unbundled_env do
|
|
56
|
-
system! "brut db rebuild --env=test"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
53
|
+
rebuild_db(before_or_after: :before)
|
|
59
54
|
run_tests
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
rebuild_db(before_or_after: :after)
|
|
56
|
+
0
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def rebuild_db(before_or_after:)
|
|
60
|
+
option, default, verb = if before_or_after == :before
|
|
61
|
+
[ :rebuild?, :rebuild_by_default?, "Rebuilding" ]
|
|
62
|
+
elsif before_or_after == :after
|
|
63
|
+
[ :rebuild_after?, :rebuild_after_by_default?, "Re-rebuilding" ]
|
|
64
|
+
else
|
|
65
|
+
bug!("before_or_after must be :before or :after")
|
|
66
|
+
end
|
|
67
|
+
if options.send(option, default: self.send(default))
|
|
68
|
+
puts "#{verb} testing datbase"
|
|
62
69
|
Bundler.with_unbundled_env do
|
|
63
70
|
system! "brut db rebuild --env=test"
|
|
64
71
|
end
|
|
65
72
|
end
|
|
66
|
-
0
|
|
67
73
|
end
|
|
68
74
|
|
|
69
75
|
private
|
|
@@ -100,9 +106,8 @@ Runs all non end-to-end tests for the app, or runs a subset of non-end-to-end te
|
|
|
100
106
|
Runs all end-to-end tests for the app, or runs a subset of end-to-end tests using RSpec-style syntax. This will run bin/test-server first, so if that fails for some reason, no tests are run.
|
|
101
107
|
}
|
|
102
108
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def run_tests
|
|
109
|
+
def run
|
|
110
|
+
rebuild_db(before_or_after: :before)
|
|
106
111
|
require "brut/spec_support/e2e_test_server"
|
|
107
112
|
test_server = Brut::SpecSupport::E2ETestServer.new(
|
|
108
113
|
bin_dir: Brut.container.project_root / "bin",
|
|
@@ -110,12 +115,15 @@ Runs all end-to-end tests for the app, or runs a subset of end-to-end tests usin
|
|
|
110
115
|
)
|
|
111
116
|
begin
|
|
112
117
|
test_server.start
|
|
113
|
-
|
|
118
|
+
run_tests
|
|
114
119
|
ensure
|
|
115
120
|
test_server.stop
|
|
121
|
+
rebuild_db(before_or_after: :after)
|
|
116
122
|
end
|
|
123
|
+
0
|
|
117
124
|
end
|
|
118
125
|
end
|
|
126
|
+
|
|
119
127
|
class Js < Brut::CLI::Commands::BaseCommand
|
|
120
128
|
def default_rack_env = "development"
|
|
121
129
|
def description = "Run JavaScript unit tests"
|
|
@@ -130,7 +138,7 @@ Runs all end-to-end tests for the app, or runs a subset of end-to-end tests usin
|
|
|
130
138
|
options.set_default(:"build-assets", true)
|
|
131
139
|
if options.build_assets?
|
|
132
140
|
Bundler.with_unbundled_env do
|
|
133
|
-
system!(
|
|
141
|
+
system!("brut build-assets all --env=test")
|
|
134
142
|
end
|
|
135
143
|
end
|
|
136
144
|
execution_context.executor.system!({ "NODE_DISABLE_COLORS" => "1" },"npx mocha #{Brut.container.js_specs_dir} --no-color --extension 'spec.js' --recursive")
|
|
@@ -46,18 +46,20 @@ class Brut::CLI::Commands::BaseCommand
|
|
|
46
46
|
def bootstrap? = false
|
|
47
47
|
|
|
48
48
|
# The default `RACK_ENV` to use for this command. This value is used when no `RACK_ENV` is present in the UNIX environment
|
|
49
|
-
# and when `--env` has not been used on the command line.
|
|
50
|
-
# not
|
|
49
|
+
# and when `--env` has not been used on the command line. This only applies to the command where
|
|
50
|
+
# the method is defined and its subclasses. It **does not** apply to subcommands of this command.
|
|
51
|
+
#
|
|
52
|
+
# The default value is 'development', mostly because a default of `nil` produces a strange error
|
|
53
|
+
# message if your intention was to load Brut configuration.
|
|
51
54
|
#
|
|
52
55
|
# @return [String|nil] If nil, Brut configuration will not be loaded and the command will run more or less as if it were a plain
|
|
53
56
|
# Ruby script. If a `String`, this value will be set as the `RACK_ENV` if it's not been otherwise specified.
|
|
54
|
-
def default_rack_env =
|
|
57
|
+
def default_rack_env = "development"
|
|
55
58
|
|
|
56
59
|
# @return [String] description of this command for use in help output
|
|
57
60
|
def description = ""
|
|
58
61
|
|
|
59
|
-
# Returns a more detaile description of the command. This can includes paragraphs which will be maintained, however
|
|
60
|
-
# any additional formatting is not rendered or used.
|
|
62
|
+
# Returns a more detaile description of the command. This can includes paragraphs (which will be maintained in the output), however any additional formatting is not rendered or used.
|
|
61
63
|
def detailed_description = nil
|
|
62
64
|
|
|
63
65
|
# @return [String] description of the arguments this command accepts. Used for documentation only.
|
|
@@ -136,19 +138,35 @@ private
|
|
|
136
138
|
# @!visibility public
|
|
137
139
|
def argv = self.execution_context.argv
|
|
138
140
|
|
|
139
|
-
#
|
|
140
|
-
|
|
141
|
-
def system!(*args,&block)
|
|
141
|
+
# Wraps `system!`, but captures the output and returns it
|
|
142
|
+
def capture!(*args)
|
|
142
143
|
output = ""
|
|
143
|
-
|
|
144
|
+
capture = ->(output_chunk) {
|
|
144
145
|
output << output_chunk
|
|
145
146
|
}
|
|
147
|
+
system!( *args, output: capture)
|
|
148
|
+
output
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Convienience methods to defer to `Brut::CLI::Commands::ExecutionContext`'s `Brut::CLI::Executor#system!`.
|
|
152
|
+
# @!visibility public
|
|
153
|
+
def system!(*args,output: :log)
|
|
154
|
+
command_output = ""
|
|
155
|
+
block = if output == :log
|
|
156
|
+
block ||= ->(output_chunk) {
|
|
157
|
+
command_output << output_chunk
|
|
158
|
+
}
|
|
159
|
+
elsif output.kind_of?(Proc)
|
|
160
|
+
block = output
|
|
161
|
+
else
|
|
162
|
+
nil
|
|
163
|
+
end
|
|
146
164
|
begin
|
|
147
165
|
self.execution_context.executor.system!(*args,&block)
|
|
148
166
|
ensure
|
|
149
|
-
if
|
|
167
|
+
if command_output.length > 0
|
|
150
168
|
progname = args.detect { it.kind_of?(String) }.split(" ")
|
|
151
|
-
|
|
169
|
+
command_output.lines.each do |line|
|
|
152
170
|
self.execution_context.logger.add(Logger::INFO, line.chomp, progname)
|
|
153
171
|
end
|
|
154
172
|
end
|
|
@@ -5,8 +5,12 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
|
|
|
5
5
|
# Create the compound command with the given list of commands. Note that these
|
|
6
6
|
# commands will be executed with *this* commands `Brut::CLI::Commands::ExecutionContext`, so these commands
|
|
7
7
|
# should all be able to work with whatever command line arguments and `argv` would be provided.
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
#
|
|
9
|
+
# @param [Array<Brut::CLI::Commands::BaseCommand>|nil] The list of commands to run when
|
|
10
|
+
# this command is executed. If nil, it is assumed you have overriden `commands` to
|
|
11
|
+
# provide the list dynamically.
|
|
12
|
+
def initialize(commands=nil)
|
|
13
|
+
@commands = commands || []
|
|
10
14
|
end
|
|
11
15
|
|
|
12
16
|
# Overrides the parent class to call each command in order. Note that if you subclass this class, **`run` is
|
|
@@ -14,7 +18,7 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
|
|
|
14
18
|
# methods on the passed `execution_context`. Methods like `puts`, `system!`, and `options` **will not work** here
|
|
15
19
|
# since they assume an ivar named `@execution_context` has been set.
|
|
16
20
|
def execute(execution_context)
|
|
17
|
-
|
|
21
|
+
commands(execution_context).each do |command|
|
|
18
22
|
execute_result = Brut::CLI::ExecuteResult.new do
|
|
19
23
|
delegate_to_command(command,execution_context)
|
|
20
24
|
end
|
|
@@ -24,4 +28,16 @@ class Brut::CLI::Commands::CompoundCommand < Brut::CLI::Commands::BaseCommand
|
|
|
24
28
|
end
|
|
25
29
|
0
|
|
26
30
|
end
|
|
31
|
+
|
|
32
|
+
# Protocol for which commands to run. You can override this to dynamically set which
|
|
33
|
+
# commands are run based on the parsed command line. Note that you must call
|
|
34
|
+
# methods like `puts` or `system!` **on the passed `execution_context`**. Do not
|
|
35
|
+
# call them directly.
|
|
36
|
+
#
|
|
37
|
+
# @param [Brut::CLI::ExecutionContext] execution_context the execution context for this
|
|
38
|
+
# command. You can use this to examine e.g. CLI options to determine which commands
|
|
39
|
+
# to return.
|
|
40
|
+
#
|
|
41
|
+
# @return [Array<Brut::CLI::Commands::BaseCommand>]
|
|
42
|
+
def commands(execution_context) = @commands
|
|
27
43
|
end
|
|
@@ -106,13 +106,7 @@ class Brut::CLI::ParsedCommandLine
|
|
|
106
106
|
@argv = remaining_argv
|
|
107
107
|
@options = Brut::CLI::Options.new(options)
|
|
108
108
|
if !@options.log_level?
|
|
109
|
-
|
|
110
|
-
@options[:'log-level'] = "debug"
|
|
111
|
-
elsif @options.quiet?
|
|
112
|
-
@options[:'log-level'] = "error"
|
|
113
|
-
else
|
|
114
|
-
@options[:'log-level'] = "info"
|
|
115
|
-
end
|
|
109
|
+
@options[:'log-level'] = "info"
|
|
116
110
|
end
|
|
117
111
|
if !@options[:'log-file']
|
|
118
112
|
log_file_path = if env["XDG_STATE_HOME"]
|
|
@@ -128,9 +122,6 @@ class Brut::CLI::ParsedCommandLine
|
|
|
128
122
|
else
|
|
129
123
|
@options[:'log-file'] = Pathname(@options[:'log-file'])
|
|
130
124
|
end
|
|
131
|
-
if @options[:'log-stdout'].nil?
|
|
132
|
-
@options[:'log-stdout'] = @options.verbose? || @options.debug?
|
|
133
|
-
end
|
|
134
125
|
rescue => ex
|
|
135
126
|
@command = if env["BRUT_DEBUG"] == "true"
|
|
136
127
|
Brut::CLI::Commands::RaiseError.new(ex)
|
|
@@ -152,8 +143,6 @@ private
|
|
|
152
143
|
"Project environment, e.g. test, development, production. Default depends on the command")
|
|
153
144
|
opts.on("--log-level=LOG_LEVEL", [ "debug", "info", "warn", "error", "fatal" ],
|
|
154
145
|
"Log level, which should be debug, info, warn, error, or fatal. Defaults to error")
|
|
155
|
-
opts.on("--debug", "--verbose", "Set log level to debug, and show log messages on stdout")
|
|
156
|
-
opts.on("--quiet", "Set log level to error")
|
|
157
146
|
opts.on("--log-file=FILE",
|
|
158
147
|
"Path to a file where log messages are written. Defaults to $XDG_CACHE_HOME/brut/logs/#{app_name}.log")
|
|
159
148
|
opts.on("--[no-]log-stdout", "Log messages to stdout in addition to the log file")
|
data/lib/brut/cli/runner.rb
CHANGED
|
@@ -77,17 +77,13 @@ class Brut::CLI::Runner
|
|
|
77
77
|
private
|
|
78
78
|
|
|
79
79
|
def load_unix_environment!(env, parsed_command_line)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
else
|
|
88
|
-
parsed_command_line.command.default_rack_env
|
|
89
|
-
end
|
|
90
|
-
end
|
|
80
|
+
env["RACK_ENV"] = if parsed_command_line.project_environment
|
|
81
|
+
parsed_command_line.project_environment.to_s
|
|
82
|
+
elsif env["RACK_ENV"]
|
|
83
|
+
env["RACK_ENV"]
|
|
84
|
+
else
|
|
85
|
+
parsed_command_line.command.default_rack_env
|
|
86
|
+
end
|
|
91
87
|
|
|
92
88
|
rack_env = RichString.from_string(env["RACK_ENV"])
|
|
93
89
|
|
|
@@ -135,9 +131,9 @@ private
|
|
|
135
131
|
if env["RACK_ENV"]
|
|
136
132
|
log_level = env["LOG_LEVEL"]
|
|
137
133
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
134
|
+
# Prevent lots of stuff from logging just
|
|
135
|
+
# because it was required
|
|
136
|
+
env["LOG_LEVEL"] = "warn"
|
|
141
137
|
|
|
142
138
|
require "#{@project_root}/app/bootstrap"
|
|
143
139
|
bootstrap = Bootstrap.new
|
|
@@ -147,6 +143,7 @@ private
|
|
|
147
143
|
bootstrap.configure_only!
|
|
148
144
|
end
|
|
149
145
|
|
|
146
|
+
# restore the log level
|
|
150
147
|
env["LOG_LEVEL"] = log_level
|
|
151
148
|
end
|
|
152
149
|
end
|
|
@@ -24,12 +24,19 @@ module Brut::SpecSupport::CLICommandSupport
|
|
|
24
24
|
args
|
|
25
25
|
end
|
|
26
26
|
@commands_executed << command
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
on_command = @on_commands.select { |it,_|
|
|
28
|
+
it == command || it.match?(command)
|
|
29
|
+
}.map { |_,it| it }.first
|
|
30
|
+
if on_command
|
|
31
|
+
if on_command[:raise_error]
|
|
29
32
|
raise Brut::CLI::SystemExecError.new(command,1)
|
|
30
|
-
elsif
|
|
31
|
-
output =
|
|
32
|
-
|
|
33
|
+
elsif on_command[:output]
|
|
34
|
+
output = on_command[:output]
|
|
35
|
+
if block_given?
|
|
36
|
+
yield(output)
|
|
37
|
+
else
|
|
38
|
+
@out.puts output
|
|
39
|
+
end
|
|
33
40
|
end
|
|
34
41
|
end
|
|
35
42
|
nil
|
data/lib/brut/version.rb
CHANGED