-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-postgres-naming
- Loading branch information
Showing
6 changed files
with
121 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require "yaml" | ||
require "cli" | ||
|
||
require "sentry" | ||
|
||
module Sentry | ||
|
||
class SentryCommand < Cli::Command | ||
|
||
command_name "sentry" | ||
|
||
SHARD_YML = "shard.yml" | ||
DEFAULT_NAME = "[process_name]" | ||
|
||
class Options | ||
|
||
def self.defaults | ||
name = Options.get_name | ||
{ | ||
name: name, | ||
process_name: "./#{name}", | ||
build: "crystal build ./src/#{name}.cr", | ||
watch: ["./src/**/*.cr", "./src/**/*.ecr"] | ||
} | ||
end | ||
|
||
def self.get_name | ||
if File.exists?(SHARD_YML) && | ||
(yaml = YAML.parse(File.read SHARD_YML)) && | ||
(name = yaml["name"]?) | ||
name.as_s | ||
else | ||
DEFAULT_NAME | ||
end | ||
end | ||
|
||
string %w(-n --name), desc: "Sets the name of the app process", | ||
default: Options.defaults[:name] | ||
|
||
string %w(-b --build), desc: "Overrides the default build command", | ||
default: Options.defaults[:build] | ||
|
||
string "--build-args", desc: "Specifies arguments for the build command" | ||
|
||
bool "--no-build", desc: "Skips the build step", default: false | ||
|
||
string %w(-r --run), desc: "Overrides the default run command", | ||
default: Options.defaults[:process_name] | ||
|
||
string "--run-args", desc: "Specifies arguments for the run command" | ||
|
||
array %w(-w --watch), | ||
desc: "Overrides default files and appends to list of watched files", | ||
default: Options.defaults[:watch] | ||
|
||
bool %w(-i --info), | ||
desc: "Shows the values for build/run commands, build/run args, and watched files", | ||
default: false | ||
|
||
help | ||
|
||
end | ||
|
||
def run | ||
|
||
if options.info? | ||
puts " | ||
name: #{options.name?} | ||
build: #{options.build?} | ||
build args: #{options.build_args?} | ||
run: #{options.run?} | ||
run args: #{options.run_args?} | ||
files: #{options.watch} | ||
" | ||
exit! code: 0 | ||
end | ||
|
||
build_args = if ba = options.build_args? | ||
ba.split " " | ||
else | ||
[] of String | ||
end | ||
run_args = if ra = options.run_args? | ||
ra.split " " | ||
else | ||
[] of String | ||
end | ||
|
||
process_runner = Sentry::ProcessRunner.new( | ||
process_name: options.name, | ||
build_command: options.build, | ||
run_command: options.run, | ||
build_args: build_args, | ||
run_args: run_args, | ||
should_build: !options.no_build?, | ||
files: options.watch | ||
) | ||
|
||
process_runner.run | ||
|
||
end | ||
end | ||
end |