feat: add check server command

This commit is contained in:
Mauricio Siu
2024-06-03 21:55:29 -06:00
parent 85fd1f2c3e
commit de871490d7
27 changed files with 5907 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
import { Command, Flags } from "@oclif/core";
import * as fs from "node:fs";
import * as path from "node:path";
const configPath = path.join(__dirname, "..", "..", "config.json");
export default class Authenticate extends Command {
static description = "Authenticate the user by saving server URL and token";
static flags = {
token: Flags.string({
char: "t",
description: "Authentication token",
required: true,
}),
url: Flags.string({ char: "u", description: "Server URL", required: true }),
};
async run() {
const { flags } = await this.parse(Authenticate);
const config = {
token: flags.token,
url: flags.url,
};
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
this.log("Authentication details saved successfully.");
}
}

View File

@@ -0,0 +1,30 @@
import {Args, Command, Flags} from '@oclif/core'
export default class CheckServer extends Command {
static override args = {
file: Args.string({description: 'file to read'}),
}
static override description = 'describe the command here'
static override examples = [
'<%= config.bin %> <%= command.id %>',
]
static override flags = {
// flag with no value (-f, --force)
force: Flags.boolean({char: 'f'}),
// flag with a value (-n, --name=VALUE)
name: Flags.string({char: 'n', description: 'name to print'}),
}
public async run(): Promise<void> {
const {args, flags} = await this.parse(CheckServer)
const name = flags.name ?? 'world'
this.log(`hello ${name} from /Users/mauricio/Documents/Github/Personal/cli/src/commands/check-server.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
}
}

View File

@@ -0,0 +1,29 @@
import { Command, Flags } from "@oclif/core";
export default class Greet extends Command {
static args = {
// Puedes agregar argumentos adicionales si lo necesitas
};
static description = "Greet the user with a message";
static examples = [
`<%= config.bin %> <%= command.id %> --name=Mau
hello Mau!
`,
];
static flags = {
name: Flags.string({
char: "n",
description: "name to greet",
required: false,
}),
};
async run(): Promise<void> {
const { flags } = await this.parse(Greet);
const name = flags.name ?? "user";
this.log(`hello ${name}!`);
}
}

View File

@@ -0,0 +1,34 @@
import { Args, Command, Flags } from "@oclif/core";
export default class Hello extends Command {
static args = {
person: Args.string({
description: "Person to say hello to",
required: true,
}),
};
static description = "Say hello";
static examples = [
`<%= config.bin %> <%= command.id %> friend --from oclif
hello friend from oclif! (./src/commands/hello/index.ts)
`,
];
static flags = {
from: Flags.string({
char: "f",
description: "Who is saying hello",
required: true,
}),
};
async run(): Promise<void> {
const { args, flags } = await this.parse(Hello);
this.log(
`hello ${args.person} from ${flags.from}! (./src/commands/hello/index.ts)`,
);
}
}

View File

@@ -0,0 +1,19 @@
import {Command} from '@oclif/core'
export default class World extends Command {
static args = {}
static description = 'Say hello world'
static examples = [
`<%= config.bin %> <%= command.id %>
hello world! (./src/commands/hello/world.ts)
`,
]
static flags = {}
async run(): Promise<void> {
this.log('hello world! (./src/commands/hello/world.ts)')
}
}

1
src/index.ts Normal file
View File

@@ -0,0 +1 @@
export {run} from '@oclif/core'