clear icon indicating copy to clipboard operation
clear copied to clipboard

Document how to use the CLI

Open ghost opened this issue 5 years ago • 5 comments

The Clear manual mentions a migration CLI, but I cannot figure out how to access it. Building with either src/clear.cr or src/clear/cli.cr as an entrypoint produces an executable that does nothing.

ghost avatar Sep 13 '20 19:09 ghost

Crystal is compiled software so it's hard to get information over your code (e.g. migrations files, model description) without compiling your code first.

To use the CLI, you need to use

# in your application entry point
Clear.with_cli do
  # your startup code goes here
  Server.start #example
end

Then you can call crystal path/to/your/entrypoint.cr -- clear --help

For now, CLI is still very basic but hopefully I will fix this soon.

anykeyh avatar Nov 21 '20 20:11 anykeyh

help

acoolstraw avatar Jan 12 '22 03:01 acoolstraw

help

Troplo avatar Jan 12 '22 03:01 Troplo

help

acoolstraw avatar Jan 12 '22 04:01 acoolstraw

CLI is good for seed + migration currently.

migrate:
	$(CRYSTAL_RUN) src/endpoints/server.cr -- clear migrate

seed:
	$(CRYSTAL_RUN) src/endpoints/server.cr -- clear seed

this is an example of one of my project using the CLI

Your bootstrap point must be written like this:

Clear.with_cli do
  Kemal.run # example
end

So far the CLI implementation is lacking a bit of features; it can manage migrations but you can run them manually and/or manage you own CLI implementation:

  Clear::Migration::Manager.instance.apply_all

anykeyh avatar Jan 13 '22 09:01 anykeyh