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 -->
# Commands
<!-- commands -->
* [`kot checkin [FILE]`](#kot-checkin-file)
* [`kot checkout [FILE]`](#kot-checkout-file)
* [`kot checkin`](#kot-checkin)
* [`kot checkout`](#kot-checkout)
* [`kot help [COMMANDS]`](#kot-help-commands)
## `kot checkin [FILE]`
## `kot checkin`
describe the command here
Check in
```
USAGE
$ kot checkin [FILE] [-n <value>] [-f]
ARGUMENTS
FILE file to read
$ kot checkin --token <value> --user-token <value>
FLAGS
-f, --force
-n, --name=<value> name to print
--token=<value> (required) Defaults to the KINGOFTIME_TOKEN environment variable.
--user-token=<value> (required) Defaults to the KINGOFTIME_USER_TOKEN environment variable.
DESCRIPTION
describe the command here
Check in
EXAMPLES
$ kot checkin
```
## `kot checkout [FILE]`
## `kot checkout`
describe the command here
Check out
```
USAGE
$ kot checkout [FILE] [-n <value>] [-f]
ARGUMENTS
FILE file to read
$ kot checkout --token <value> --user-token <value>
FLAGS
-f, --force
-n, --name=<value> name to print
--token=<value> (required) Defaults to the KINGOFTIME_TOKEN environment variable.
--user-token=<value> (required) Defaults to the KINGOFTIME_USER_TOKEN environment variable.
DESCRIPTION
describe the command here
Check out
EXAMPLES
$ 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 {
static description = 'describe the command here'
export default class Checkout extends Command {
static description = 'Check in'
static examples = [
'<%= config.bin %> <%= command.id %>',
]
static flags = {
// 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'}),
}
static flags = tokenFlags
public async run(): Promise<void> {
const {args, flags} = await this.parse(Checkin)
const name = flags.name ?? 'world'
this.log(`hello ${name} from src/commands/checkin.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
const {flags} = await this.parse(Checkout)
console.log(`token: ${flags.token}`)
console.log(`userToken: ${flags.userToken}`)
}
}

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 {
static description = 'describe the command here'
static description = 'Check out'
static examples = [
'<%= config.bin %> <%= command.id %>',
]
static flags = {
// 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'}),
}
static flags = tokenFlags
public async run(): Promise<void> {
const {args, flags} = await this.parse(Checkout)
const name = flags.name ?? 'world'
this.log(`hello ${name} from src/commands/checkout.ts`)
if (args.file && flags.force) {
this.log(`you input --force and --file: ${args.file}`)
}
const {flags} = await this.parse(Checkout)
console.log(`token: ${flags.token}`)
console.log(`userToken: ${flags.userToken}`)
}
}

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
})
}