Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to default the [Yn] responses for the Ruby "gem clean" command?

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?

like image 470
Anupam Avatar asked Nov 05 '11 18:11

Anupam


2 Answers

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.

like image 147
mu is too short Avatar answered Sep 20 '22 00:09

mu is too short


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.

like image 42
Thilo Avatar answered Sep 20 '22 00:09

Thilo