Skip to content

Custom Command Guidelines

Deeton Rushton edited this page Sep 22, 2023 · 2 revisions

Here are the guidelines for creating your own custom commands.

Name

The commands name should be all lowercase. This isn't strict and wont cause any errors, but it's annoying when trying to fly through some commands and you're having to press shift all the time.

// Good!
public override string Name => "command";
// Bad!
public override string Name => "CommandName";

Description

The commands description should be short and sweet. Just a short piece of information to get a grasp of what it will do in general. You should save all of the juicy information for your documentation string.

// Good!
public override string Description => "This command will change the directory.";
// Bad!
public override string Description => "This command will change the directory by doing this and that and this and that. The arguments are ...."; 

Execution

In the Run function, always call base.Run(...) first. This enables the command to output information using the builtin functions and will allow your command to work with the lastranat command.

When outputting normal information, use base.WriteLine(...), this will automatically display what command is outputting that information and save the output to specific storage points for other commands to access it.

When outputting errors, use base.WriteError(...). This will automatically display a big error "ERROR" before your text and saves the output for other commands.

When asking for user input, use base.ReadLine(...). This will automatically use terminal.Ui.GetLine and takes a prompt.

public override int Run(List<string> args, IConsole parent) {
  // Good!
  WriteLine("Hi there!");
  // Bad! 
  Console.WriteLine("What am I doing...");
  // Good!
  var input = ReadLine("Am I great? (y/N): ");
  // Bad!
  var input = Console.ReadLine(); // wtf?
}

OnInit override

When overriding this function, only output useful information as this will be displayed on the screen and may affect whoever is using the console.

public override void OnInit(IConsole parent) {
  parent.Ui.DisplayLineMarkup("[red italic]LOG[/]: This is useful information");
}

DocString

This is where you add as much information about the command as possible. This is the information that will be displayed when the user runs docs on your command. This should contain EVERYTHING there is to know about your command.

// Bad...
public override string DocString => "Some command";
Clone this wiki locally