Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 999407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:20:51+00:00 2026-05-16T07:20:51+00:00

I’m currently working on a CLI app in Ruby, I’m using Trollop ( http://trollop.rubyforge.org/

  • 0

I’m currently working on a CLI app in Ruby, I’m using Trollop (http://trollop.rubyforge.org/) for dealing with cli arguments.

I’d also like to implement the possibility of storing the required options in ~/.mycfg as well as cwd/.mycfg, the latter taking precedence.

The behaviour I’m trying to implement is:

If .mycfg exists in the current working directory, load default options from there, otherwise, if it exists in the user’s home directory, load options from there.

I will then override those options if they are also passed as arguments.

The question is, what format should the config file be in? I’ve thought about YAML, but then how to I merge the array that Trollop generates for the parameters with the YAML, or the other way around.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:20:51+00:00Added an answer on May 16, 2026 at 7:20 am

    One easy thing you can try is to modify ARGV before Trollop processes it. First, read in your config file and convert the data stored there into an array of equivalent command-line options. Now, prepend that array to ARGV and then set Trollop loose. That way, Trollop will parse all of your arguments (whether they came from the config file or from the CLI). Since your config file parameters are now listed before the CLI parameters, any CLI option will override a matching config file option (since later options override earlier options).

    Your config file can be in any format you want to use, but sometimes the simplest form can be the easiest. Try a plain text format where the config file contents are simply the exact parameters that you want to pass to your script. That is to say, the contents of the file are written such that calling:

    your_script.rb `cat optionsfile` -more -CLI -options
    

    would work as expected. Storing options in this format makes them easy to edit and easy to process. Simply read in the file (should be a single line) and call String.split(' ') to split the options into an array, just like they would appear when coming from ARGV. A variation is to have a multi-line config file with one CLI parameter per line. In that case, you would build up your array of options one line at a time using something like File.each_line(configfile) {|x| options_array << x}.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.