I regularly use the Ruby gem clean
command to keep the local gem repository in shape.
However, due to dependency issues, many a times the command returns a prompt such as:
XXXXX-1.0.6 depends on [YYYYYY (~> 0.8.4)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]
While this is simple enough, it requires manual intervention (for the [Yn]
response), and hence this is preventing me from creating a simple cron
script to automate this process.
Any ideas on how to default the response for these gem
prompts?
You should have a yes
command, the OSX version has this to say:
YES(1) BSD General Commands Manual YES(1)
NAME
yes -- be repetitively affirmative
SYNOPSIS
yes [expletive]
DESCRIPTION
yes outputs expletive, or, by default, ``y'', forever.
HISTORY
The yes command appeared in 4.0BSD.
4th Berkeley Distribution June 6, 1993 4th Berkeley Distribution
So perhaps this will work:
yes n | gem clean
gem clean
might be reading directly from the terminal rather than the standard input. In that case, you might have expect
kicking around:
Expect is a program that "talks" to other interactive programs according to a script. Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script.
So you could write an expect
script to respond to the expected prompts with "y" or "n" as desired.
This should work:
echo|gem clean
It'll act like hitting return at the prompt. 'y' being the default, it'll run gem clean
to completion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With