Add tokenFlags to checkin/checkout commands

This commit is contained in:
Adam Millerchip 2023-04-15 00:14:07 +09:00
parent 92d108ee17
commit 0b021187b8
4 changed files with 46 additions and 59 deletions

View file

@ -24,49 +24,43 @@ USAGE
<!-- usagestop --> <!-- usagestop -->
# Commands # Commands
<!-- commands --> <!-- commands -->
* [`kot checkin [FILE]`](#kot-checkin-file) * [`kot checkin`](#kot-checkin)
* [`kot checkout [FILE]`](#kot-checkout-file) * [`kot checkout`](#kot-checkout)
* [`kot help [COMMANDS]`](#kot-help-commands) * [`kot help [COMMANDS]`](#kot-help-commands)
## `kot checkin [FILE]` ## `kot checkin`
describe the command here Check in
``` ```
USAGE USAGE
$ kot checkin [FILE] [-n <value>] [-f] $ kot checkin --token <value> --user-token <value>
ARGUMENTS
FILE file to read
FLAGS FLAGS
-f, --force --token=<value> (required) Defaults to the KINGOFTIME_TOKEN environment variable.
-n, --name=<value> name to print --user-token=<value> (required) Defaults to the KINGOFTIME_USER_TOKEN environment variable.
DESCRIPTION DESCRIPTION
describe the command here Check in
EXAMPLES EXAMPLES
$ kot checkin $ kot checkin
``` ```
## `kot checkout [FILE]` ## `kot checkout`
describe the command here Check out
``` ```
USAGE USAGE
$ kot checkout [FILE] [-n <value>] [-f] $ kot checkout --token <value> --user-token <value>
ARGUMENTS
FILE file to read
FLAGS FLAGS
-f, --force --token=<value> (required) Defaults to the KINGOFTIME_TOKEN environment variable.
-n, --name=<value> name to print --user-token=<value> (required) Defaults to the KINGOFTIME_USER_TOKEN environment variable.
DESCRIPTION DESCRIPTION
describe the command here Check out
EXAMPLES EXAMPLES
$ kot checkout $ kot checkout

View file

@ -1,30 +1,18 @@
import {Args, Command, Flags} from '@oclif/core' import {Command} from '@oclif/core'
import {tokenFlags} from '../tokenFlags'
export default class Checkin extends Command { export default class Checkout extends Command {
static description = 'describe the command here' static description = 'Check in'
static examples = [ static examples = [
'<%= config.bin %> <%= command.id %>', '<%= config.bin %> <%= command.id %>',
] ]
static flags = { static flags = tokenFlags
// flag with a value (-n, --name=VALUE)
name: Flags.string({char: 'n', description: 'name to print'}),
// flag with no value (-f, --force)
force: Flags.boolean({char: 'f'}),
}
static args = {
file: Args.string({description: 'file to read'}),
}
public async run(): Promise<void> { public async run(): Promise<void> {
const {args, flags} = await this.parse(Checkin) const {flags} = await this.parse(Checkout)
console.log(`token: ${flags.token}`)
const name = flags.name ?? 'world' console.log(`userToken: ${flags.userToken}`)
this.log(`hello ${name} from src/commands/checkin.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
} }
} }

View file

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

17
src/tokenFlags.ts Normal file
View file

@ -0,0 +1,17 @@
import {Flags} from '@oclif/core'
const tokenVar = 'KINGOFTIME_TOKEN'
const userTokenVar = 'KINGOFTIME_USER_TOKEN'
export const tokenFlags = {
token: Flags.string({
env: tokenVar,
description: `Defaults to the ${tokenVar} environment variable.`,
required: true
}),
'user-token': Flags.string({
env: userTokenVar,
description: `Defaults to the ${userTokenVar} environment variable.`,
required: true
})
}