Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command-line interface #389

Merged
merged 61 commits into from
Dec 4, 2020
Merged

Command-line interface #389

merged 61 commits into from
Dec 4, 2020

Conversation

mmkal
Copy link
Contributor

@mmkal mmkal commented Nov 19, 2020

@papb this is a draft for the CLI I've been playing around with.

It's using ts-command-line for argument-parsing/help-text generation so it's pretty well documented and handles errors and typos well.

It's technically not a CLI though. It adds a runAsCLI() method to the Umzug prototype so that users can create their own CLIs easily.

CC @ceelogre this could provide an alternative to sequelize cli for your use case in #360. There's a prerelease package published to npm which can be installed with npm i umzug@beta-cli.

Usage:

Set up an umzug instance and call .runAsCLI():

// migrator.js

const { Umzug } = require('umzug')

const umzug = new Umzug({
  migrations: { glob: 'migrations/*.js' },
  logger: console,
})

umzug.runAsCLI()

Now that file is a runnable CLI script:

node migrator --help # shows all commands and documentation
node migrator up  # applies migrations
node migrator down # reverts last migration
node migrator pending # lists pending migrations
node migrator executed # lists executed migrations
node migrator create --name foo.js # creates a new migration file with timestamp prefix and suffix foo.js

node migrator up -- help # shows help and parameters for the up command
node migrator down -- help # shows help and parameters for the down command
node migrator pending -- help # shows help and parameters for the pending command
node migrator executed --help # shows help and parameters for the executed command
node migrator create --help # shows help and parameters for the create command

@papb
Copy link
Member

papb commented Nov 24, 2020

Hi @mmkal! This looks awesome! Thank you so much. Sorry for taking long. Today I plan on taking a closer look on everything here in Umzug.

@mmkal mmkal marked this pull request as ready for review November 29, 2020 13:17
Copy link
Member

@papb papb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to be continued)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
codegen.js Outdated Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/cli.ts Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/umzug.ts Outdated Show resolved Hide resolved
src/umzug.ts Outdated Show resolved Hide resolved
src/cli.ts Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
src/cli.ts Show resolved Hide resolved
src/cli.ts Outdated Show resolved Hide resolved
@mmkal mmkal merged commit ae4b3eb into master Dec 4, 2020
@mmkal mmkal deleted the cli-initial branch December 4, 2020 16:55
@papb
Copy link
Member

papb commented Dec 30, 2020

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants