diff --git a/README.md b/README.md index 5c20c7a..e7a2783 100644 --- a/README.md +++ b/README.md @@ -24,49 +24,43 @@ USAGE # 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 ] [-f] - -ARGUMENTS - FILE file to read + $ kot checkin --token --user-token FLAGS - -f, --force - -n, --name= name to print + --token= (required) Defaults to the KINGOFTIME_TOKEN environment variable. + --user-token= (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 ] [-f] - -ARGUMENTS - FILE file to read + $ kot checkout --token --user-token FLAGS - -f, --force - -n, --name= name to print + --token= (required) Defaults to the KINGOFTIME_TOKEN environment variable. + --user-token= (required) Defaults to the KINGOFTIME_USER_TOKEN environment variable. DESCRIPTION - describe the command here + Check out EXAMPLES $ kot checkout diff --git a/src/commands/checkin.ts b/src/commands/checkin.ts index ec2ee5b..1a0cce5 100644 --- a/src/commands/checkin.ts +++ b/src/commands/checkin.ts @@ -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 { - 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}`) } } diff --git a/src/commands/checkout.ts b/src/commands/checkout.ts index b9f13ac..a3cedf3 100644 --- a/src/commands/checkout.ts +++ b/src/commands/checkout.ts @@ -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 { - 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}`) } } diff --git a/src/tokenFlags.ts b/src/tokenFlags.ts new file mode 100644 index 0000000..b8cc04c --- /dev/null +++ b/src/tokenFlags.ts @@ -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 + }) +}