# Commandline

Commandline objects help handling command lines specifying processes to execute.

The class can be used to define a command line as nested elements or as a helper to define a command line by an application.

`<someelement>
<acommandline executable="/executable/to/run">
<argument value="argument 1" />
<argument line="argument_1 argument_2 argument_3" />
<argument value="argument 4" />
</acommandline>
</someelement>
` The element `someelement` must provide a method `createAcommandline` which returns an instance of this class.

author | thomas.haas@softwired-inc.com
author | Stefan Bodewig
package | phing.types

### Methods

## __construct

    __construct(null $to_process = null)

throws |

### Arguments

#### $to_process

`null`

## __copy

    __copy() : \Commandline

### Response

`\Commandline`

## __toString

    __toString() : string

### Response

`string`

## addArguments

    addArguments( $line)

### Arguments

#### $line

``

## Clear out the whole command line.

    clear()

## Clear out the arguments but leave the executable in place for another operation.

    clearArgs()

## Creates an argument object and adds it to our list of args.

    createArgument(boolean $insertAtStart = false) : \CommandlineArgument

Each commandline object has at most one instance of the argument class.

### Arguments

#### $insertAtStart

`boolean`

if true, the argument is inserted at the beginning of the list of args, otherwise it is appended.

### Response

`\CommandlineArgument`

## Return a marker.

    createMarker() : \CommandlineMarker

This marker can be used to locate a position on the commandline - to insert something for example - when all parameters have been set.

### Response

`\CommandlineMarker`

## Returns a String that describes the arguments suitable for verbose output before a call to <code>Runtime.exec(String[])</code>

    describeArguments( $args = null, \ignore|integer $offset) : string

### Arguments

#### $args

``

arguments to use (default is to use current class args)

#### $offset

`\ignore|integer`

ignore entries before this index

### Response

`string`

## Returns a String that describes the command and arguments suitable for verbose output before a call to <code>Runtime.exec(String[])</code>.

    describeCommand(array $args = null) : string

This method assumes that the first entry in the array is the executable to run.

### Arguments

#### $args

`array`

CommandlineArgument[] to use

### Response

`string`

## Returns all arguments defined by <code>addLine</code>, <code>addValue</code> or the argument object.

    getArguments()

## Returns the executable and all defined arguments.

    getCommandline() : array

### Response

`array`

## getExecutable

    getExecutable() : string

### Response

`string`

## Put quotes around the given String if necessary.

    quoteArgument( $argument, boolean $escape = false) : string

static

If the argument doesn't include spaces or quotes, return it as is. If it contains double quotes, use single quotes - else surround the argument by double quotes.

exception | BuildException if the argument contains both, single and double quotes.
throws |

### Arguments

#### $argument

``

#### $escape

`boolean`

### Response

`string`

## Sets the executable to run.

    setExecutable( $executable)

### Arguments

#### $executable

``

## size

    size() : integer

### Response

`integer`

Number of components in current commandline.

## Quotes the parts of the given array in way that makes them usable as command line arguments.

    toString( $lines, boolean $escape = false) : string

static

throws |

### Arguments

#### $lines

``

#### $escape

`boolean`

### Response

`string`

## translateCommandline

    translateCommandline(string $to_process) : array

static

throws |

### Arguments

#### $to_process

`string`

### Response

`array`

### Constants

## DISCLAIMER

    DISCLAIMER

### Properties

## CommandlineArguments[]

    arguments : array

var | CommandlineArguments[]

### Type(s)

`array`

## Full path (if not on %PATH% env var) to executable program.

    executable : string

var |

### Type(s)

`string`