limbo/cli
Pere Diaz Bou 70c5cf3970 Merge 'Refactor Cli Repl Commands to use clap' from Pedro Muniz
This PR changes the argument parsing and matching to use Clap instead of
our own handrolled one. This makes it much easier to add new commands
and modify existing ones by using the full power of clap's derive
macros. It also produces nice error and help messages for us. However,
there is a bug in Clap that is not correctly modifying the `display
name` in the help section. So the command would appear as `show` instead
of `.show` in the help messages. This is very minimal, but if this is a
blocker for this PR we can just overwrite the help message in its
entirety. Also using Clap would enable us to use its autocomplete crate
to generate autocompletions for these special repl commands which would
be a huge win when compared to the `sqlite3` cli.
This is the current help message:
```sh

Limbo SQL Shell Help
==============
Welcome to the Limbo SQL Shell! You can execute any standard SQL command here.
In addition to standard SQL commands, the following special commands are available:

Usage: <COMMAND>

Commands:
  exit       Exit this program with return-code CODE
  quit       Quit the shell
  open       Open a database file
  schema     Print this message or the help of the given subcommand(s) Display schema for a table
  output     Set output file (or stdout if empty)
  mode       Set output display mode
  opcodes    Show vdbe opcodes
  cd         Change the current working directory
  show       Display information about settings
  nullvalue  Set the value of NULL to be printed in 'list' mode
  echo       Toggle 'echo' mode to repeat commands before execution
  tables     Display tables
  import     Import data from FILE into TABLE
  load       Loads an extension library
  dump       Dump the current database as a list of SQL statements
  listvfs    List vfs modules available
  help       Print this message or the help of the given subcommand(s)

Usage Examples:
---------------
1. To quit the Limbo SQL Shell:
   .quit

2. To open a database file at path './employees.db':
   .open employees.db

3. To view the schema of a table named 'employees':
   .schema employees

4. To list all tables:
   .tables

5. To list all available SQL opcodes:
   .opcodes

6. To change the current output mode to 'pretty':
   .mode pretty

7. Send output to STDOUT if no file is specified:
   .output

8. To change the current working directory to '/tmp':
   .cd /tmp

9. Show the current values of settings:
   .show

10. To import csv file 'sample.csv' into 'csv_table' table:
   .import --csv sample.csv csv_table

11. To display the database contents as SQL:
   .dump

12. To load an extension library:
   .load /target/debug/liblimbo_regexp

13. To list all available VFS:
   .listvfs

Note:
- All SQL commands must end with a semicolon (;).
- Special commands start with a dot (.) and are not required to end with a semicolon.

```
If we need more information on a specific command, we can leverage CLAP
and do for instance:
```sh
.open -h
```

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #1110
2025-04-01 11:40:14 +02:00
..
commands correct vfs command 2025-03-30 03:22:44 -03:00
docs/internal docs for cli 2025-03-30 02:41:48 -03:00
app.rs Merge 'Refactor Cli Repl Commands to use clap' from Pedro Muniz 2025-04-01 11:40:14 +02:00
build.rs adding table colors 2025-03-06 15:52:20 -03:00
Cargo.toml remove debug clap 2025-03-30 01:46:24 -03:00
helper.rs Improve CLI color scheme 2025-03-21 19:21:25 +02:00
input.rs adding listvfs to extra helpful message 2025-03-30 02:52:07 -03:00
main.rs display name in clap is buggy 2025-03-30 01:46:24 -03:00
opcodes_dictionary.rs fix: lint warnings 2024-07-08 22:43:11 +05:30
SQL.sublime-syntax highlight candidate 2025-03-06 16:33:23 -03:00