codeflood logo

Custom Commands

One design goal for Revolver was to be a platform for custom tool development and allow users to create their own commands.

Defining a Command

Revolver commands must implement the Revolver.Core.Commands.ICommand, Revolver.Core interface. As a convenience commands may subclass Revolver.Core.Commands.BaseCommand, Revolver.Core which implements the interface and handles initialisation.

Command Arguments

Arguments passed to the command through the command line are automatically mapped to properties of the command class. Attributes are used to facilitate this mapping and control how it’s performed.

The following attributes are supported:


Revolver.Core.Commands.DescriptionAttribute

Provides a description of the command which is used in the help system.

Revolver.Core.Commands.FlagParameterAttribute

For boolean properties. This argument is either present or not.

Revolver.Core.Commands.ListParameterAttribute

For IList<string> properties. Collects all unmatched arguments from the argument list.

Revolver.Core.Commands.NamedParameterAttribute

For arguments passed by name.

Revolver.Core.Commands.NoSubstitutionAttribute

Indicates token substitution should not be performed for the property.

Revolver.Core.Commands.NumberedParameterAttribute

For arguments passed in order.

Revolver.Core.Commands.OptionalAttribute

Indicates the argument is optional. Only used as an indicator in the help system, not enforced by the parser.

Example

Here’s a quick example of a custom command that uses automatic argument mapping.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public class MyCommand : BaseCommand
{
[NumberedParameter(0, "name")]
[Description("The name to use")]
public string Name { get; set; }

[FlagParameter("c")]
[Description("Changes the operation or something")]
[Optional]
public bool Unclone { get; set; }

[NamedParameter("a", "attribute")]
[Description("Provide a something")]
[Optional]
public int Attribute { get; set; }

public override CommandResult Run()
{
// implement command
}

public override string Description()
{
return "Description of what the command does";
}

public override void Help(HelpDetails details)
{
// Add help details here
}
}

Reference

The best reference available for implementing commands in Revolver would be the Revolver source itself. Have a look over the commands at https://github.com/codeflood/revolver/tree/master/Revolver.Core/Commands