Issue #14386 has been updated by k0kubun (Takashi Kokubun).


> I have nothing against it. I think it would change existing behaviour
though, if I read http://ruby-doc.org/core-2.5.0/Kernel.html#method-i-system
correctly

I don't get what you mean. Do you mean existing program may be passing :assert_status in the second (or the third if env is given) Hash?

It's already taking the same options as Process.spawn, and I'm not going to change Process.spawn too here. So it would make a little hard to understand the behavior of Kernel.#system's options. But I can't imagine why it becomes breaking.

> If an option would be used to make system raise instead of returning a boolean, then it would make more sense to return the combined err + out output instead of true or false.

I agree that returning true would not make sense and such method would be convenient too. But the behavior is not consistent with the current Kernel.#system behavior. So probably it's better to use the different method name or to add a new option to Kernel.#`.

----------------------------------------
Feature #14386: Add option to let Kernel.#system raise error instead of returning false
https://bugs.ruby-lang.org/issues/14386#change-69728

* Author: k0kubun (Takashi Kokubun)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I sometimes write code like:

~~~ ruby
system('git pull origin master') || raise('Failed to execute: git pull origin master')
system('bundle check || bundle install') || raise('Failed to execute: bundle check || bundle install')
~~~

Using rake, we can simplify the above code to the following one, but there's no way to do that outside Rakefile. (Note that I just want to do the same thing as "bash -e", the error message is actually not important.)

~~~ ruby
sh 'git pull origin master'
sh 'bundle check || bundle install'
~~~

If we add the following option, we can simplify such code even when we're not on a rake task. I'm not sure whether it's a good name or not though.

~~~ ruby
system 'git pull origin master', assert_status: true
system 'bundle check || bundle install', assert_status: true
# => RuntimeError: Command failed with status (1): bundle check || bundle install
~~~



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>