v8-archive icon indicating copy to clipboard operation
v8-archive copied to clipboard

Build a new CLI console

Open jooola opened this issue 4 years ago • 16 comments

This PR is the work initiated by the issue #1613. It is the first step for the creation of a complete and easily maintainable CLI tool for the directus api project.

Before merging, we need to fix few things :

  • Were can I get the application name, description and version. It shouldn't be hardcoded.

  • Should we make only one entry point for the CLI ? We could either build a fresh new CLI with a second entry point (directus-next or else), or mix the 2 CLI.

If we need to mix both CLI Console, I suggest to first run the old commands, and if the command isn't found, run the new one and let it handle the usage display (this just came out of my mind without more thinking).

A deprecated notice will also be required I think.

Another idea would be to make only alias commands with the old syntax that trigger the new command.

@directus/team

jooola avatar Jan 03 '20 20:01 jooola

A small overview of the new CLI

jo@jofix: symfony_cli_commands ↓4↑1 ✚1…1 ~/git/directus/api $ ./bin/directus-next                       
directus-next v8.3.1

Usage:
  command [options] [arguments]

Options:
  -h, --help                   Display this help message
  -q, --quiet                  Do not output any message
  -V, --version                Display this application version
      --ansi                   Force ANSI output
      --no-ansi                Disable ANSI output
  -n, --no-interaction         Do not ask any interactive question
      --base-path[=BASE-PATH]  Path to directus base directory [default: "/home/jo/git/directus/api"]
  -v|vv|vvv, --verbose         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help                Displays help for a command
  list                Lists commands
 cache
  cache:clear         Clear all objects from cache
 config
  config:create       Create a new configuration file
 db
  db:upgrade          Upgrade the database schema
 maintenance
  maintenance:off     Disable maintenance mode
  maintenance:on      Enable maintenance mode
  maintenance:status  Get maintenance mode status
 user
  user:create         Create a new user
  user:delete         Delete an existing user
  user:password       Change an existing user password

jooola avatar Jan 04 '20 01:01 jooola

Looking good so far. Are you doing only the base or you'll try to build the commands too?

WoLfulus avatar Jan 05 '20 06:01 WoLfulus

@WoLfulus I don't know, should I ? The commands are in a separate branch but I could make a single big pull request.

jooola avatar Jan 05 '20 13:01 jooola

I asked just to know if there's more coming or if this PR was intended to be a boilerplate for a new CLI.

WoLfulus avatar Jan 06 '20 12:01 WoLfulus

Lets keep everything CI related in one PR, so we can merge / release it at once. We can move it into a new branch on this repo and go from there, or keep pushing to this PR. Doesn't change much

rijkvanzanten avatar Jan 06 '20 20:01 rijkvanzanten

Ok I'll push the rest of my work in this PR.

jooola avatar Jan 06 '20 22:01 jooola

It's still a WIP since I didn't write all the commands. But some commands needs a bit more attention, I hopped I could move any of the old command logic to dedicated files so it can be reused somewhere else.

jooola avatar Jan 06 '20 23:01 jooola

@jooola that would be ideal, but a pretty big undertaking in the current codebase. I think we should focus on getting the IO of the CLI optimized now, and restructure where the code is located when we're moving to Laravel as a whole too

rijkvanzanten avatar Jan 08 '20 15:01 rijkvanzanten

@jooola @bjgajjar and I will be reviewing / helping out with the CLI today 🙂

Are there any specific things you have on your to-do list for the CLI?

rijkvanzanten avatar Jan 08 '20 15:01 rijkvanzanten

directus-next 8.3.1

Usage:
  command [options] [arguments]

Options:
  -h, --help                   Display this help message
  -q, --quiet                  Do not output any message
  -V, --version                Display this application version
      --ansi                   Force ANSI output
      --no-ansi                Disable ANSI output
  -n, --no-interaction         Do not ask any interactive question
      --base-path[=BASE-PATH]  Path to directus base directory [default: "/home/jo/git/directus/api"]
  -v|vv|vvv, --verbose         Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help                Displays help for a command
  list                Lists commands
 cache
  cache:clear         Clear all objects from cache
 config
  config:create       Create a new configuration file
 db
  db:install          Populate the database
  db:upgrade          Upgrade the database schema
 maintenance
  maintenance:off     Disable maintenance mode
  maintenance:on      Enable maintenance mode
  maintenance:status  Get maintenance mode status
 user
  user:create         Create a new user
  user:delete         Delete an existing user
  user:password       Change an existing user password

jooola avatar Jan 08 '20 16:01 jooola

@rijkvanzanten @bjgajjar feel free to push on this branch.

jooola avatar Jan 08 '20 16:01 jooola

@jooola - Thanks for the quick fix.

But it seems like I'm missing something. Can you please help me to figure out the below error?

image

It occurs in PHP 7.3.8 and I installed all the composer dependencies.

binal-7span avatar Jan 08 '20 17:01 binal-7span

@bjgajjar It might be a Symfony Console version mismatch. We upgraded phinx to match the latest version of this Component, you might still use the old one.

Have you tried with a fresh vendor folder ? If that doesn't work I'll need more infos.

jooola avatar Jan 08 '20 17:01 jooola

Yes - I tried with a fresh vendor folder too [ Removing the vendor as well as composer.lock]

Still getting the same error.

binal-7span avatar Jan 08 '20 17:01 binal-7span

I'll need more information, let's not hijack this thread, we can continue debugging this on Slack or another ticket.

jooola avatar Jan 08 '20 17:01 jooola

I started to implement some of the commands, the easy ones. I might have overlooked some things, I tried only to keep the code clean and I trust the InstallerUtils/Service to do the required checks.

This feels like a huge change now and I wonder how you folks feel about this PR ?

jooola avatar Feb 12 '20 14:02 jooola