Table of contents
- Why a CLI?
- Create a new CLI
- How to use it
- Future plans
- Generating HttpClient?
- Storing the token
- Code generation
In this post we will see how to create a Cli for your abp application.
Why a CLI?
The CLI is a great way to automate repetitive tasks. I use it to import large amounts of data into the database, to create new entities, to seed dummy data, etc.
Create a new CLI
To create a new CLI, you need to install the cli dotnet new template.
dotnet new install Anto.Cli.Template
Then you can create a new CLI project.
dotnet new cli-template -o MyProject --api myabpproject.com
Note: The --api parameter is the url of your abp project.
How to use it
The CLI is a dotnet core console application. You can run it with the following command.
dotnet run -- --help
- Seed Tenant
- Seed User
- Import data from csv
Once you have created the cli there are few things you need to do.
- Create a new OpenIdConnect client in your abp project for the cli.
- Update the ClientId and Scope in the
The CLI uses the abp REST API to communicate with the abp project. But that means you need to generate the HttpClient before you can use it. To do that, I have used
nswag to generate the client. To generate the client, you need to run the following command.
Note: You need to have
package.json file for more details.
Storing the token
The CLI stores the token in the
access-token.bin file. If you want to change the location of the file, you can change it in the
CliPaths.cs file. the token is not encrypted, keep that in mind.
This cli uses
plop to generate code. You can find the templates in the
plop-templates folder. You can add your own templates there.
Right now, there is only 3 templates. you can just run the following command to generate the code.
Note: Make sure you have install npm packages before running the command.
This is a very simple CLI, but it can be very useful. I hope you like it.