Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds src entry path and infers from shard.yml #61

Merged
merged 4 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ Build/Runs your crystal application, watches files, and rebuilds/reruns app on f
## Installation

To install in your project, from the root directory of your project, run:

```bash
curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/master/install.cr | crystal eval
```

If using Crystal version `0.24.2` try the following:

```bash
curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/crystal-v0.24.2/install.cr | crystal eval
```

If using Crystal version `0.23.1` or lower try the following:

```bash
curl -fsSLo- https://raw.githubusercontent.com/samueleaton/sentry/crystal-v0.23.1/install.cr | crystal eval
```
Expand Down Expand Up @@ -50,12 +53,14 @@ Assuming `sentry.cr` was correctly placed in `[your project name]/dev/sentry.cr`
```

Example

```bash
$ ./sentry -h

Usage: ./sentry [options]
-n NAME, --name=NAME Sets the display name of the app process (default name: <your_app_here>)
-b COMMAND, --build=COMMAND Overrides the default build command
--src=PATH Sets the entry path for the main crystal file (default is inferred from shards.yaml)
-b COMMAND, --build=COMMAND Overrides the default build command (will override --src flag)
--build-args=ARGS Specifies arguments for the build command
--no-build Skips the build step
-r COMMAND, --run=COMMAND Overrides the default run command
Expand Down Expand Up @@ -103,6 +108,7 @@ This shows the values for the build command, run command, and watched files.
```

Example

```
$ ./sentry -i

Expand Down Expand Up @@ -148,6 +154,7 @@ See the `YAML.mapping` definition in the `Config` class in [the `/src/sentry.cr`
Sentry output is colorized by default. To remove colorization, pass the `--no-color` argument.

Example

```bash
./sentry --no-color
```
Expand All @@ -157,6 +164,7 @@ Example
See [CRYSTAL_API.md](./CRYSTAL_API.md)

## Why?

(1) It is tiring to have to stop and restart an app on every change.

(2) Docker!
Expand Down
9 changes: 6 additions & 3 deletions src/sentry.cr
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module Sentry

property? colorize : Bool = true

property? install_shards : Bool = false
property src_path : String = "./src/#{Sentry::Config.shard_name}.cr"

property? colorize : Bool = false
property? install_shards : Bool = false

setter build_args : String = ""

Expand All @@ -41,6 +41,7 @@ module Sentry
@display_name = nil
@sets_display_name = false
@info = false
@src_path = "./src/#{Sentry::Config.shard_name}.cr"
@build = nil
@build_args = ""
@run = nil
Expand Down Expand Up @@ -68,7 +69,7 @@ module Sentry
@build : String?

def build
@build ||= "crystal build ./src/#{self.class.shard_name}.cr"
@build ||= "crystal build #{self.src_path}"
end

def build=(new_command : String)
Expand Down Expand Up @@ -118,6 +119,7 @@ module Sentry
self.watch = other.watch unless other.watch.empty?
self.install_shards = other.install_shards?
self.colorize = other.colorize?
self.src_path = other.src_path
end

def to_s(io : IO)
Expand All @@ -129,6 +131,7 @@ module Sentry
info: #{info}
build: #{build}
build_args: #{build_args}
src_path: #{src_path}
run: #{run}
run_args: #{run_args}
watch: #{watch}
Expand Down
20 changes: 19 additions & 1 deletion src/sentry_cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,34 @@ end
cli_config = Sentry::Config.new
cli_config_file_name = ".sentry.yml"

# Set the default entry src path from shard.yml
if shard_yml && (targets = shard_yml["targets"]?)
if targets
# use targets[<shard_name>]["main"] if exists
if name && (main_path = targets.dig?(name, "main"))
cli_config.src_path = main_path.as_s
elsif ((raw = targets.raw) && raw.is_a?(Hash))
# otherwise, use the first key you find targets[<first_key>]["main"]
if (first_key = raw.keys[0]?) && (main_path = targets.dig?(first_key, "main"))
cli_config.src_path = main_path.as_s
end
end
end
end

OptionParser.parse do |parser|
parser.banner = "Usage: ./sentry [options]"
parser.on(
"-n NAME",
"--name=NAME",
"Sets the display name of the app process (default name: #{Sentry::Config.shard_name})") { |name| cli_config.display_name = name }
parser.on(
"--src=PATH",
"Sets the entry path for the main crystal file (default inferred from shard.yaml)") { |path| cli_config.src_path = path }
parser.on(
"-b COMMAND",
"--build=COMMAND",
"Overrides the default build command") { |command| cli_config.build = command }
"Overrides the default build command (will override --src flag)") { |command| cli_config.build = command }
parser.on(
"--build-args=ARGS",
"Specifies arguments for the build command") { |args| cli_config.build_args = args }
Expand Down