-
Notifications
You must be signed in to change notification settings - Fork 108
/
register.ts
43 lines (39 loc) · 1.96 KB
/
register.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
import { Command } from "commander";
import { configureOptions } from "../../../../core/utils";
import { init } from "./init";
import { DEFAULT_CONFIG } from "../../../../config";
export default function registerCommand(program: Command) {
const dbCommand = program.command("db [command] [options]").description("Manage your database");
const dbInitCommand = new Command()
.command("init")
.usage("[options]")
.description("initialize database connection configurations for your static web app")
.requiredOption(
"-t, --database-type <database type>",
"(Required) The type of the database you want to connect (mssql, postgresql, cosmosdb_nosql, mysql, cosmosdb_postgresql)."
)
.option(
"-f, --folder-name <folder name>",
"A folder name to override the convention database connection configuration folder name (ensure that you update your CI/CD workflow files accordingly).",
DEFAULT_CONFIG.folderName
)
.option("-cs, --connection-string <connection string>", "The connection string of the database you want to connect.")
.option(
"-nd, --cosmosdb_nosql-database <cosmosdb nosql database>",
"The database of your cosmosdb account you want to connect (only needed if using cosmosdb_nosql database type)."
)
.option("-nc, --cosmosdb_nosql-container <cosmosdb nosql container>", "The container of your cosmosdb account you want to connect.")
.action(async (_options: SWACLIConfig, command: Command) => {
const options = await configureOptions(undefined, command.optsWithGlobals(), command, "db init", false);
await init(options);
})
.addHelpText(
"after",
`
Examples:
swa db init --database-type mssql --connection-string $YOUR_CONNECTION_STRING_ENV
swa db init --database-type cosmosdb_nosql --cosmosdb_nosql-database myCosmosDB --connection-string $YOUR_CONNECTION_STRING_ENV
`
);
dbCommand.addCommand(dbInitCommand).copyInheritedSettings; // For supporting dab init
}