-
-
Notifications
You must be signed in to change notification settings - Fork 105
Add run command #298
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
Add run command #298
Conversation
Thanks. Can you write a few integration tests, to check that the targets are built and run, and the exit status properly reported? |
For sure. Is there already a way to evaluate the exit status somewhere in the tests? This is my first go with minitest, so it's a little difficult to debug my tests. I see that |
Tests added, but 2 of them are behaving unexpectedly. I've verified the functionality in a dummy repo and using the The 2 tests in question are expected to throw a Any help is welcome. |
The YAML blocks create a YAML with 2 leading spaces, it should be the following (notice that the blocking YAML is indented): str = <<-YAML
name: xxx
version: 0.0.0
YAML |
Hmm, there appears to be an issue beyond just that. Modifying as suggested did not make a difference. |
Yes, youre not changing the current directory in some tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few error message changes. All raised Error exceptions follow this schema a capitalized Term to be colorized followed by a lowercase sentence. For example Error missing ...
or Failed to ...
.
Also, I think the run
command should just pass STDIN, STDOUT and STDERR as-is. Maybe even replacing the current process with exec
— but I'm not sure it's possible with Crystal.
@ysbaddaden Was this something that still needs to be addressed or just a nice to have? |
It should really use |
Co-Authored-By: Johannes Müller <johannes.mueller@smj-fulda.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One nitpick, but it looks great to me.
@ysbaddaden Anything else needed on this one before getting approved? |
Co-Authored-By: Sijawusz Pur Rahnama <sija@sija.pl>
Can we have a spec checking how to pass ARGV values from the shards run command to the actual command? I guess it should be |
I've confirmed manually that passing ARGV values works, but simulating it using the run function from factories.cr has proven to be difficult. It spits errors out to the console when the test is run saying it cannot read ARGV[0] which is being passed. Here is the WIP test code: it "runs specific target with args" do
File.write(File.join(application_path, "src", "cli_with_args.cr"), "puts __FILE__;args = ARGV[0]")
File.write File.join(application_path, "shard.yml"), <<-YAML
name: build
version: 0.1.0
targets:
app:
main: src/cli_with_args.cr
YAML
Dir.cd(application_path) do
run "shards run app --no-color -- foo"
File.exists?(bin_path("app")).should be_true
`#{bin_path("app")}`.chomp.should eq(File.join(application_path, "src", "cli_with_args.cr"))
end
end Could this be something specific with how ARGV is handled in a shell environment vs. through Process.exec? Any help appreciated. |
Anything I can do to help move this feature over the finish line? |
@silasb The only piece missing was a test for the above. I'm able to verify functionality manually, but testing it properly proved to be difficult because of how the commands are fed to the shell. |
I no longer use Crystal personally and don't have time to get these tests running, so I'll be closing this PR out. My branch will still be accessible if someone wanted to use it to finish #157. |
Introduces `shards run`, similar to `shards build`, that builds and runs the specified target, providing a unified interface to developers. With this, a developer can directly use `shards run <target>` in a single step without having first to compile (build) and then execute it with `./bin/target`. No need for a script or wrapper. This is inspired by `crystal build` and `crystal run` user experience (with the difference that `crystal run` creates a temporary binary). This is very helpful for automatic rebuild scenarios, where a process is monitoring your code and can rebuild and relaunch your application. When invoking `shards run`, it will first build the target (with the supplied options) and then invoke it, passing the extra options: $ shards run myapp --stats -- --args Is the same as: $ shards build myapp --stats $ ./bin/myapp --args If the target exits with error, the exit code is passed back. Resolves crystal-lang#157 Relates crystal-lang#298 Co-authored-by: Elliot DeNolf <65888+denolfe@users.noreply.github.com>
Adds
shards run
command. Resolves #157.