← 全部工具

infrablocks/lino

热度 75 更新于 开发与构建

Command line builder and execution utilities.

githubauto-collected

安装

暂未验证可直接使用的安装命令,请查看项目官方文档或 Release。

Lino

Command line building and execution utilities.

Installation

Add this line to your application's Gemfile:

gem 'lino'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lino

Usage

Lino allows commands to be built and executed:

require 'lino'
  
command_line = Lino.builder_for_command('ruby')
    .with_flag('-v')
    .with_option('-e', 'puts "Hello"')
    .build
    
puts command_line.array
# => ['ruby', '-v', '-e', 'puts "Hello"']
  
puts command_line.string
# => ruby -v -e puts "Hello"

commandline.execute

ruby 2.3.1p112 (2016-04-26 revision 54768) [x8664-darwin15]

Hello


### Building command lines

`Lino` supports building command lines via instances of the 
`Lino::Builder::CommandLine` class. `Lino::Builder::CommandLine` allows a 
number of different styles of commands to be built. The object built by 
`Lino::Builder::CommandLine` is an instance of `Lino::Model::CommandLine`, which
represents the components and context of a command line and allows the 
command line to be executed. 

Aside from the object model, `Lino::Model::CommandLine` instances have two 
representations, accessible via the `#string` and `#array` instance methods.

The string representation is useful when the command line is intended to be executed by a shell, where quoting is important. However, it can present a security risk if the components (option values, arguments, environment variables) of the command line are user provided. For this reason, the array representation is preferable and is the representation used by default whenever Lino executes commands.

#### Getting a command line builder