Published on

Creating a Cli for your ABP Application.

Table of Contents

Introduction

I this post we will see how to create a cli for you .Net application.

Why?

Sometimes when I am working on a project and I need to do some repetitive tasks, I create a cli for that. For example, Importing data from a csv file to the database. this is a repetitive task and I don't want to do it manually every time. But I don't want to create a UI for that. for these cases CLI can be very useful.

Installation

First we need to install the .net template.

dotnet new install Anto.Cli.Template

Creating a new project

Now we can create a new project using the template.

dotnet new cli-template -o MyProject --api myabpproject.com

this will create a new project in the MyProject folder. The default project comes with few sample commands.

Adding a new command

you can use the plop generator to add a new command.

plop

this will ask you for the command name. make sure you install the npm packages before running the plop command.

npm install

Running the project

you can run the project using the following command.

dotnet run -- --help

This will show you the list of commands.

Data Seeding

I have created 2 data seeding commands. one for the users and one for the tenants. These will seed random data to you application after you login. you can remove these commands if you don't need them. I have created them for my personal use.

Conclusion

This is a very simple template. you can add more commands to it. I will add more commands to it in the future. I created this template to seed some data to my application after I login. I hope you find this useful. let me know if you have any questions.