Skip to content

Commit

Permalink
add docs command
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jul 24, 2019
1 parent ba14493 commit 34b2eac
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/prisma2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
"mocha": "6.1.4",
"mz": "2.7.0",
"nexus-prisma": "0.0.1-beta.4",
"open": "^6.4.0",
"pkg-up": "3.1.0",
"prisma-test-utils": "^0.2.5",
"serialize-error": "^4.1.0",
"strip-ansi": "^5.2.0",
"terminal-link": "^1.3.0",
"tmp": "^0.1.0",
"ts-jest": "24.0.2",
"ts-mocha": "6.0.0",
Expand Down
36 changes: 36 additions & 0 deletions cli/prisma2/src/Docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import chalk from 'chalk'
import { Command, Env, format, HelpError } from '@prisma/cli'
import open from 'open'
import terminalLink from 'terminal-link'
import { link } from './link'

/**
* $ prisma COMMAND_NAME docs
*/
export class Docs implements Command {
public static new(commandName: string, url: string): Docs {
return new Docs(commandName, url)
}

// static help template
private static help = commandName =>
format(`
Opens the docs page for ${commandName}.
`)
private constructor(private readonly commandName: string, private readonly url: string) {}

// parse arguments
public async parse(argv: string[]): Promise<string | Error> {
console.log(`Opening ${chalk.greenBright(this.commandName)} docs at ${link(this.url)}`)
await open(this.url)
return ''
}

// help message
public help(error?: string): string | HelpError {
if (error) {
return new HelpError(`\n${chalk.bold.red(`!`)} ${error}\n${Docs.help}`)
}
return Docs.help(this.commandName)
}
}
2 changes: 2 additions & 0 deletions cli/prisma2/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { predefinedGenerators } from './generators'
import { Generate } from './Generate'
import chalk from 'chalk'
import { capture } from './capture'
import { Docs } from './Docs'
export { Photon } from '@prisma/studio-transports'

/**
Expand All @@ -52,6 +53,7 @@ async function main(): Promise<number> {
save: LiftSave.new(env),
up: LiftUp.new(env),
down: LiftDown.new(env),
docs: Docs.new('lift', 'https://github.com/prisma/prisma2/tree/master/docs'),
},
env,
),
Expand Down
8 changes: 8 additions & 0 deletions cli/prisma2/src/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import terminalLink from 'terminal-link'
import chalk from 'chalk'

export function link(url) {
return terminalLink(url, url, {
fallback: url => chalk.underline(url),
})
}
7 changes: 7 additions & 0 deletions cli/prisma2/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,13 @@ onetime@^5.1.0:
dependencies:
mimic-fn "^2.1.0"

open@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9"
integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==
dependencies:
is-wsl "^1.1.0"

optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
Expand Down

0 comments on commit 34b2eac

Please sign in to comment.