Table of Contents

Class CliCommand

Namespace
ZeroInstall.Commands
Assembly
0install.dll

Represents a command invoked via command-line arguments.

public abstract class CliCommand : ScopedOperation
Inheritance
CliCommand
Derived
Inherited Members

Remarks

Specific sub-classes of this class are used to handle a commands like "0install COMMAND [OPTIONS]".

Constructors

CliCommand(ICommandHandler)

Creates a new command.

protected CliCommand(ICommandHandler handler)

Parameters

handler ICommandHandler

A callback object used when the user needs to be asked questions or informed about download and IO tasks.

Fields

AdditionalArgs

Feeds to add, terms to search for, etc.

protected readonly List<string> AdditionalArgs

Field Value

List<string>

Options

The command-line argument parser used to evaluate user input.

protected readonly OptionSet Options

Field Value

OptionSet

Properties

AdditionalArgsMax

The maximum number of AdditionalArgs allowed. Checked in Parse(IReadOnlyList<string>).

protected virtual int AdditionalArgsMax { get; }

Property Value

int

AdditionalArgsMin

The minimum number of AdditionalArgs allowed. Checked in Parse(IReadOnlyList<string>).

protected virtual int AdditionalArgsMin { get; }

Property Value

int

Description

A short description of what this command does.

public abstract string Description { get; }

Property Value

string

FullName

The full name of this command (including sub-commands) as used in command-line arguments in lower-case.

public string FullName { get; }

Property Value

string

Handler

A callback object used when the user needs to be asked questions or informed about download and IO tasks.

public ICommandHandler Handler { get; }

Property Value

ICommandHandler

HelpText

The help text describing the available command-line options and their effects.

protected string HelpText { get; }

Property Value

string

Usage

The additional arguments to be displayed after the command name in the help text.

public abstract string Usage { get; }

Property Value

string

Methods

AddDiscoverOptions()

Adds command-line options related to ImplementationDiscovery.

protected void AddDiscoverOptions()

AsParallel<T>(IEnumerable<T>)

Prepares the elements for parallel processing while respecting MaxParallelDownloads and CancellationToken.

protected ParallelQuery<T> AsParallel<T>(IEnumerable<T> elements)

Parameters

elements IEnumerable<T>

Returns

ParallelQuery<T>

Type Parameters

T

Create(string?, ICommandHandler)

Creates a new CliCommand based on a name.

public static CliCommand Create(string? commandName, ICommandHandler handler)

Parameters

commandName string

The command name to look for; case-insensitive; can be null.

handler ICommandHandler

A callback object used when the user needs to be asked questions or informed about download and IO tasks.

Returns

CliCommand

The requested CliCommand or DefaultCommand if commandName was null.

Exceptions

OptionException

commandName is an unknown command.

IOException

There was a problem accessing a configuration file or one of the stores.

UnauthorizedAccessException

Access to a configuration file or one of the stores was not permitted.

InvalidDataException

A configuration file is damaged.

CreateAndParse(IReadOnlyList<string>, ICommandHandler)

Parses command-line arguments, automatically creating an appropriate CliCommand.

public static CliCommand CreateAndParse(IReadOnlyList<string> args, ICommandHandler handler)

Parameters

args IReadOnlyList<string>

The command-line arguments to be parsed.

handler ICommandHandler

A callback object used when the user needs to be asked questions or informed about download and IO tasks.

Returns

CliCommand

The newly created CliCommand after Parse(IReadOnlyList<string>) has been called.

Exceptions

OperationCanceledException

The user asked to see help information, version information, etc..

OptionException

args contains unknown options or specified an unknown command.

IOException

A problem occurred while creating a directory.

UnauthorizedAccessException

Creating a directory is not permitted.

InvalidDataException

A configuration file is damaged.

FormatException

An URI, local path, version number, etc. is invalid.

Execute()

Executes the commands specified by the command-line arguments. Must call Parse(IReadOnlyList<string>) first!

public abstract ExitCode Execute()

Returns

ExitCode

The exit status code to end the process with.

Remarks

When inheriting this method is usually replaced.

Exceptions

OperationCanceledException

The user canceled the task.

OptionException

The number of arguments passed in on the command-line is incorrect.

WebException

A file could not be downloaded from the internet.

NotSupportedException

A file format, protocol, etc. is unknown or not supported.

IOException

A downloaded file could not be written to the disk or extracted or an external application or file required by the solver could not be accessed.

UnauthorizedAccessException

An operation failed due to insufficient rights.

InvalidDataException

A problem occurred while deserializing an XML file.

SignatureException

The signature data could not be handled for some reason.

FormatException

An URI, local path, version number, etc. is invalid.

DigestMismatchException

An Implementation's Archives don't match the associated ManifestDigest.

SolverException

The ISolver was unable to provide Selections that fulfill the Requirements.

ImplementationNotFoundException

One of the ImplementationBases is not cached yet.

ExecutorException

The IExecutor was unable to process the Selections.

FetchAll(IEnumerable<Implementation>)

Downloads a set of Implementations to the ZeroInstall.Store in parallel.

protected void FetchAll(IEnumerable<Implementation> implementations)

Parameters

implementations IEnumerable<Implementation>

The Implementations to be downloaded.

Exceptions

OperationCanceledException

A download or IO task was canceled from another thread.

WebException

A file could not be downloaded from the internet.

NotSupportedException

A file format, protocol, etc. is unknown or not supported.

IOException

A downloaded file could not be written to the disk or extracted.

UnauthorizedAccessException

Write access to IImplementationStore is not permitted.

DigestMismatchException

An Implementation's Archives don't match the associated ManifestDigest.

GetCommandName(ref IReadOnlyList<string>)

Determines the command name specified in the command-line arguments.

public static string? GetCommandName(ref IReadOnlyList<string> args)

Parameters

args IReadOnlyList<string>

The command-line arguments to search for a command name. The collection is replaced with a copy with the command removed from it.

Returns

string

The name of the command that was found or null if none was specified.

Parse(IReadOnlyList<string>)

Parses command-line arguments and stores the result in the command.

public virtual void Parse(IReadOnlyList<string> args)

Parameters

args IReadOnlyList<string>

The command-line arguments to be parsed.

Exceptions

OperationCanceledException

The user asked to see help information, version information, etc..

OptionException

args contains unknown options.

IOException

An IO operation failed.

UnauthorizedAccessException

More privileges are required.

UriFormatException

The URI or local path specified is invalid.

SupportedValues<T>()

Generates a localized instruction string describing multiple selectable enum values.

protected static string SupportedValues<T>()

Returns

string

Type Parameters

T

The enum type to list values for.

SupportedValues<T>(params T[])

Generates a localized instruction string describing multiple selectable values.

protected static string SupportedValues<T>(params T[] values)

Parameters

values T[]

The values to list.

Returns

string

Type Parameters

T