Skip to main content

Developing a Command Line Extension

To execute commands from NDCLI, you need a command line extension for NDCLI.

Although the processing logic for model validation and generation is the same, the mechanism for executing these processes via commands from NDCLI is different.

For this reason, the Next Design desktop version of the extension itself cannot be used as is.

The following explains how to develop a command line extension.

Project Settings

Project Type

  • Develop as a C# class library.

Extension DLL Name

  • The DLL file name that stores the entry point class for the command line extension (described below) should contain the string "CliExtension."
  • Since the project name is usually the same as the DLL file name, we recommend including "CliExtension" in the project name.

Framework Selection

  • Select .NET Standard 2.0.
    (This will allow it to run in a Linux environment.)

Installing the Package

  • Add the following package to your referenced packages:
  • NextDesign.Cli.ExtensionFramework

Build Settings

  • Set the following command in Visual Studio's post-build event:
    (This will output all files required at runtime, including dependent libraries, to the publish folder.)
dotnet publish "$(ProjectPath)" -c $(ConfigurationName) --no-build
tip

Implementing the Code

Implementing the Entry Point Class

  • Define a class that inherits from the ExtensionBase class to serve as the entry point.
using NextDesign.Cli.ExtensionFramework;
using DensoCreate.Cli.Framework;

namespace MyExtension.CliExtension
{
public class MyCliExtension : ExtensionBase
{
///<summary>
///Constructor
///</summary>
public MyCliExtension() : base("MyCliExtension")
{
}
}
}

Implementing a Command

  • Define a class inheriting from the Command class for each command you want to implement.
  • You can define multiple commands in a single command line extension.
  • To add subcommands, define a class inheriting from the SubCommand class.
caution
  • If a command and subcommand are specified on the command line, the command's OnExecute method will not be called. Arguments specified with the command will be ignored and will not be considered required.
  • Command processing will only be performed if a command is specified without a subcommand.
using NextDesign.Cli.ExtensionFramework;
using DensoCreate.Cli.Framework;

namespace MyCliExtension
{
///<summary>
///MyCommand command
///</summary>
public class MyCommand : Command
{
///<summary>
///Constructor
///</summary>
public MyCommand() : base("MyCommand", "MyCommand command description")
{
AddOption<string>(new string[] { "--option", "-o" }, "Option description", true);
RegisterHandler(nameof(OnExecute));

//Register subcommand
AddSubCommand<MySubCommand>();
}

///<summary>
///Handler execution
///</summary>
///<param name="option"></param>
private void OnExecute(string option)
{
Console.WriteLine($"MyCommand executed. option: {option}");
}
}

///<summary>
///Subcommand of SubCommand
///</summary>
public class MySubCommand : SubCommand
{
///<summary>
///Constructor
///</summary>
public MySubCommand() : base("MySubCommand", "Description of MySubCommand command")
{
AddOption<string>(new string[] { "--subOption", "-o" }, "Description of subOption");
RegisterHandler(nameof(OnExecute));
}

///<summary>
///Handler execution
///</summary>
private void OnExecute(string subOption)
{
Console.WriteLine($"MySubCommand executed. subOption: {subOption}");
}
}
}

Deploying the extension to the execution environment

Store the files output to the publish folder as a build result in one of the following folders.

  • If only you will be using the extension

  • Windows version:
    "%HOMEPATH%\AppData\Local\DENSO CREATE\Next Design CLI\extensions\{subfolder for each extension}\"

  • Linux version:
    "$HOME/.local/share/DENSO CREATE/Next Design CLI/extensions/{subfolder for each extension}/"

  • If all users of NDCLI on that computer will be using the extension

  • {NDCLI installation path}\extensions\{subfolder for each extension}