Skip to content

Latest commit

 

History

History
1142 lines (425 loc) · 11 KB

File metadata and controls

1142 lines (425 loc) · 11 KB

CompletionInput

An input specialized for shell completion.

This input allows unfinished option names or values and exposes what kind of completion is expected.

Constants

Constant Visibility Type Value
TYPE_ARGUMENT_VALUE public 'argument_value'
TYPE_OPTION_VALUE public 'option_value'
TYPE_OPTION_NAME public 'option_name'
TYPE_NONE public 'none'

Properties

tokens

private $tokens

currentIndex

private $currentIndex

completionType

private $completionType

completionName

private $completionName

completionValue

private $completionValue

Methods

fromString

Converts a terminal string into tokens.

public static fromString(string $inputStr, int $currentIndex): self

This is required for shell completions without COMP_WORDS support.

  • This method is static.

Parameters:

Parameter Type Description
$inputStr string
$currentIndex int

fromTokens

Create an input based on an COMP_WORDS token list.

public static fromTokens(string[] $tokens,  $currentIndex): self
  • This method is static.

Parameters:

Parameter Type Description
$tokens string[] the set of split tokens (e.g. COMP_WORDS or argv)
$currentIndex **** the index of the cursor (e.g. COMP_CWORD)

bind

{@inheritdoc}

public bind(\Symfony\Component\Console\Input\InputDefinition $definition): void

Parameters:

Parameter Type Description
$definition \Symfony\Component\Console\Input\InputDefinition

getCompletionType

Returns the type of completion required.

public getCompletionType(): string

TYPE_ARGUMENT_VALUE when completing the value of an input argument TYPE_OPTION_VALUE when completing the value of an input option TYPE_OPTION_NAME when completing the name of an input option TYPE_NONE when nothing should be completed

Return Value:

One of self::TYPE_* constants. TYPE_OPTION_NAME and TYPE_NONE are already implemented by the Console component


getCompletionName

The name of the input option or argument when completing a value.

public getCompletionName(): string|null

Return Value:

returns null when completing an option name


getCompletionValue

The value already typed by the user (or empty string).

public getCompletionValue(): string

mustSuggestOptionValuesFor

public mustSuggestOptionValuesFor(string $optionName): bool

Parameters:

Parameter Type Description
$optionName string

mustSuggestArgumentValuesFor

public mustSuggestArgumentValuesFor(string $argumentName): bool

Parameters:

Parameter Type Description
$argumentName string

parseToken

protected parseToken(string $token, bool $parseOptions): bool

Parameters:

Parameter Type Description
$token string
$parseOptions bool

getOptionFromToken

private getOptionFromToken(string $optionToken): ?\Symfony\Component\Console\Input\InputOption

Parameters:

Parameter Type Description
$optionToken string

getRelevantToken

The token of the cursor, or the last token if the cursor is at the end of the input.

private getRelevantToken(): string

isCursorFree

Whether the cursor is "free" (i.e. at the end of the input preceded by a space).

private isCursorFree(): bool

__toString

Returns a stringified representation of the args passed to the command.

public __toString(): string

Inherited methods

__construct

public __construct(\Symfony\Component\Console\Input\InputDefinition $definition = null): mixed

Parameters:

Parameter Type Description
$definition \Symfony\Component\Console\Input\InputDefinition

setTokens

protected setTokens(array $tokens): mixed

Parameters:

Parameter Type Description
$tokens array

parse

Processes command line arguments.

protected parse(): mixed
  • This method is abstract.

parseToken

protected parseToken(string $token, bool $parseOptions): bool

Parameters:

Parameter Type Description
$token string
$parseOptions bool

parseShortOption

Parses a short option.

private parseShortOption(string $token): mixed

Parameters:

Parameter Type Description
$token string

parseShortOptionSet

Parses a short option set.

private parseShortOptionSet(string $name): mixed

Parameters:

Parameter Type Description
$name string

parseLongOption

Parses a long option.

private parseLongOption(string $token): mixed

Parameters:

Parameter Type Description
$token string

parseArgument

Parses an argument.

private parseArgument(string $token): mixed

Parameters:

Parameter Type Description
$token string

addShortOption

Adds a short option value.

private addShortOption(string $shortcut, mixed $value): mixed

Parameters:

Parameter Type Description
$shortcut string
$value mixed

addLongOption

Adds a long option value.

private addLongOption(string $name, mixed $value): mixed

Parameters:

Parameter Type Description
$name string
$value mixed

getFirstArgument

{@inheritdoc}

public getFirstArgument(): mixed

hasParameterOption

{@inheritdoc}

public hasParameterOption(mixed $values, bool $onlyParams = false): mixed

Parameters:

Parameter Type Description
$values mixed
$onlyParams bool

getParameterOption

{@inheritdoc}

public getParameterOption(mixed $values, mixed $default = false, bool $onlyParams = false): mixed

Parameters:

Parameter Type Description
$values mixed
$default mixed
$onlyParams bool

__toString

Returns a stringified representation of the args passed to the command.

public __toString(): string

bind

Binds the current Input instance with the given arguments and options.

public bind(\Symfony\Component\Console\Input\InputDefinition $definition): mixed

Parameters:

Parameter Type Description
$definition \Symfony\Component\Console\Input\InputDefinition

validate

Validates the input.

public validate(): mixed

isInteractive

Is this input means interactive?

public isInteractive(): bool

setInteractive

Sets the input interactivity.

public setInteractive(bool $interactive): mixed

Parameters:

Parameter Type Description
$interactive bool

getArguments

Returns all the given arguments merged with the default values.

public getArguments(): (string|bool|int|float|array|null)[]

getArgument

Returns the argument value for a given argument name.

public getArgument(string $name): mixed

Parameters:

Parameter Type Description
$name string

setArgument

Sets an argument value by name.

public setArgument(string $name, mixed $value): mixed

Parameters:

Parameter Type Description
$name string
$value mixed The argument value

hasArgument

Returns true if an InputArgument object exists by name or position.

public hasArgument(string $name): bool

Parameters:

Parameter Type Description
$name string

getOptions

Returns all the given options merged with the default values.

public getOptions(): (string|bool|int|float|array|null)[]

getOption

Returns the option value for a given option name.

public getOption(string $name): mixed

Parameters:

Parameter Type Description
$name string

setOption

Sets an option value by name.

public setOption(string $name, mixed $value): mixed

Parameters:

Parameter Type Description
$name string
$value mixed The option value

hasOption

Returns true if an InputOption object exists by name.

public hasOption(string $name): bool

Parameters:

Parameter Type Description
$name string

escapeToken

Escapes a token through escapeshellarg if it contains unsafe chars.

public escapeToken(string $token): string

Parameters:

Parameter Type Description
$token string

setStream

Sets the input stream to read from when interacting with the user.

public setStream(mixed $stream): mixed

Parameters:

Parameter Type Description
$stream mixed The input stream

getStream

Returns the input stream.

public getStream(): resource|null