$HOME install

S

Simon Strandgaard

One of my friends (Johan Gade) asked me this question:

How do I install a ruby package within my homedir ?

I suggested him to use gnu-stow.. but he insisted.

The package uses Minero Aoki's install.rb.
Is it possible ?


Any suggestions on how to do non-root installation ?
 
S

Simon Strandgaard

Hi,

In mail "$HOME install"


Yes. Try this:

$ ruby install.rb config --prefix=$HOME
$ ruby install.rb setup
$ ruby install.rb install


thought: $RUBYLIB should also point to the lib-dir ?


Thanks for install.rb/setup.rb :)
 
J

Joey Gibson

I've been wanting an easy way to output usage info for my programs that use
GetoptLong, without having to duplicate all the option information; once
for the creation of the GetoptLong object, and again in a help message.
I've taken a crack at altering GetoptLong to support a "usage" method that
essentially does what I want.

Basically what it does is have you include a fourth parameter for each
option: the description. This is used internally, then removed from each
array, the collection is then passed to the original initialize method for
regular processing. Calling the usage method of your GetoptLong object will
print out a user-defined message (or a default) and then iterates over the
options, printing both long and short versions, and the description. I've
included the code below in a test program. I'm not finished with it, but I
wanted to share it. I want to make the output a little prettier and maybe
make it more flexible. I don't know yet. I welcome any suggestions or
comments.

####
require 'getoptlong'

class GetoptLong
alias old_init initialize

def initialize(*options)
@descriptions = Hash.new

options.each do |arg|
key = arg[0..1]
desc = arg[3]
@descriptions[key] = desc
arg.pop
end

old_init(*options)
end

def usage(message="Usage:")
puts "#{message}"

@descriptions.sort.each do |k, v|
printf "%15s => %-40s\n", k.join(", "), v
end
end
end

opts = GetoptLong.new(["--date", "-d", GetoptLong::REQUIRED_ARGUMENT,
"specify a date"],
["--quiet", "-q", GetoptLong::NO_ARGUMENT, "be verry
quiet"],
["--help", "-h", GetoptLong::NO_ARGUMENT, "Print this
help page"])

opts.each do |opt, arg|
case opt
when "--date"
puts "Date passed"
when "--help"
opts.usage("Usage: goltest [options]\n\n")
# opts.usage
exit
end
end
 
R

Robert Klemme

That's a nice coincidence - or a proof for the theory of morphogenetic
fields: I was just today wanting to have the same functionality and
equally thought how nice it would be to simply have an additional string
parameter containing the usage.

Hmmm, let's see... I'd override set_options instead of initialize because
that is the method douing the work. Try this:

class GetoptLong
alias old_set_options set_options

def set_options(*options)
@descriptions = []
@opt_help = "Options:\n"

options.each do |arg|
if hasDescription? arg
@opt_help << sprintf("%-20s: %s\n", arg[0..-3].join( ',
' ), arg.pop )
else
@opt_help << arg[0..-2].join( ', ' ) << "\n"
end
end

@opt_help << "\n"

old_set_options(*options)
end

def usage(message="Usage:")
puts message
puts @opt_help
end

private

def hasDescription?(optarray)
case optarray[-1]
when GetoptLong::REQUIRED_ARGUMENT,
GetoptLong::NO_ARGUMENT,
GetoptLong::OPTIONAL_ARGUMENT
false
else
true
end
end
end


Regards

robert
 
J

Joey Gibson

||| def has_description?(optarray)
||| optarray.length == 3
||| end

That should have been a 4...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top