rprogram
所属分类:工具库
开发工具:Ruby
文件大小:0KB
下载次数:0
上传日期:2022-10-06 04:07:57
上 传 者:
sh-1993
说明: 用于围绕命令行程序创建包装器的库。,
(A library for creating wrappers around command-line programs.,)
文件列表:
.document (27, 2022-10-05)
.gemtest (0, 2022-10-05)
.rspec (32, 2022-10-05)
.yardopts (63, 2022-10-05)
ChangeLog.md (5017, 2022-10-05)
Gemfile (195, 2022-10-05)
LICENSE.txt (1061, 2022-10-05)
Rakefile (209, 2022-10-05)
gemspec.yml (622, 2022-10-05)
lib/ (0, 2022-10-05)
lib/rprogram.rb (78, 2022-10-05)
lib/rprogram/ (0, 2022-10-05)
lib/rprogram/argument.rb (681, 2022-10-05)
lib/rprogram/exceptions.rb (48, 2022-10-05)
lib/rprogram/exceptions/ (0, 2022-10-05)
lib/rprogram/exceptions/program_not_found.rb (65, 2022-10-05)
lib/rprogram/non_option.rb (1526, 2022-10-05)
lib/rprogram/option.rb (3093, 2022-10-05)
lib/rprogram/option_list.rb (770, 2022-10-05)
lib/rprogram/program.rb (10173, 2022-10-05)
lib/rprogram/rprogram.rb (471, 2022-10-05)
lib/rprogram/sudo.rb (170, 2022-10-05)
lib/rprogram/sudo_task.rb (2191, 2022-10-05)
lib/rprogram/system.rb (7732, 2022-10-05)
lib/rprogram/task.rb (12149, 2022-10-05)
lib/rprogram/version.rb (64, 2022-10-05)
rprogram.gemspec (2024, 2022-10-05)
spec/ (0, 2022-10-05)
spec/classes/ (0, 2022-10-05)
spec/classes/aliased_program.rb (117, 2022-10-05)
spec/classes/ls_program.rb (105, 2022-10-05)
spec/classes/ls_selinux_task.rb (126, 2022-10-05)
spec/classes/ls_task.rb (336, 2022-10-05)
spec/classes/named_program.rb (93, 2022-10-05)
spec/non_option_spec.rb (1334, 2022-10-05)
... ...
# DEPRECATED: This library has been deprecated by [command_mapper](https://github.com/postmodern/command_mapper.rb).
# RProgram
* [Source](https://github.com/postmodern/rprogram)
* [Issues](https://github.com/postmodern/rprogram/issues)
* [Documentation](http://rubydoc.info/gems/rprogram/frames)
## Description
RProgram is a library for creating wrappers around command-line programs.
RProgram provides a Rubyful interface to programs and all their options
or non-options. RProgram can also search for programs installed on a
system.
## Features
* Safely executes individual programs and their separate command-line
arguments, to prevent command or option injection.
* Supports using Ruby 1.9 [exec options](http://rubydoc.info/stdlib/core/1.9.2/Kernel#spawn-instance_method).
* Supports specifying environment variables of a process
(only available on Ruby 1.9).
* Allows running programs with `IO.popen` (only available on Ruby 1.9).
* Allows running programs under `sudo`.
* Provides cross-platform access to the `PATH` environment variable.
* Supports leading/tailing non-options.
* Supports long-options and short-options.
* Supports custom formatting of options.
## Examples
First, create the class to represent the options of the program, using
{RProgram::Task} as the base class:
require 'rprogram/task'
class MyProgTask < RProgram::Task
# map in the short-options
short_option :flag => '-o', :name => :output
short_option :flag => '-oX', :name => :xml_output
# map in long options
long_option :flag => '--no-resolv', :name => :disable_resolv
# long_option can infer the :name option, based on the :flag
long_option :flag => '--mode'
# options can also take multiple values
long_option :flag => '--includes', :multiple => true
# options with multiple values can have a custom separator character
long_option :flag => '--ops',
:multiple => true,
:separator => ','
# define any non-options (aka additional arguments)
non_option :tailing => true, :name => :files
end
Next, create the class to represent the program you wish to interface with,
using {RProgram::Program} as the base class:
require 'my_prog_task'
require 'rprogram/program'
class MyProg < RProgram::Program
# identify the file-name of the program
name_program 'my_prg'
# add a top-level method which finds and runs your program.
def self.my_run(options={},&block)
self.find.my_run(options,&block)
end
# add a method which runs the program with MyProgTask.
def my_run(options={},&block)
run_task(MyProgTask.new(options,&block))
end
end
Finally, run your program with options or a block:
MyProgram.my_run(:mode => :fast, :files => ['test1'])
# => true
MyProgram.my_run do |my_prog|
my_prog.includes = ['one', 'two', 'three']
my_prog.mode = :safe
my_prog.output = 'output.txt'
my_prog.files = ['test1.txt', 'test2.txt']
end
# => true
## Install
$ gem install rprogram
## License
Copyright (c) 2007-2012 Hal Brodigan
See {file:LICENSE.txt} for license information.
近期下载者:
相关文件:
收藏者: