Skip to content

Commit

Permalink
feat(cli): organized CLI (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-20 authored Jan 31, 2025
1 parent 5985088 commit 32e146e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@
## How to use

1. Extract the queries [statically](#static-extractor) or [dynamically](#dynamic-extractor)
2. [Get your table schema](#getting-table-schemas)
3. [Generate cache plan](#generate-cache-plan)
4. [Generate the driver](#generate-the-driver)
5. [Switch the driver](#switch-the-driver)
1. [Install isuc CLI](#install-isuc-cli)
2. Extract the queries [statically](#static-extractor) or [dynamically](#dynamic-extractor)
3. [Get your table schema](#getting-table-schemas)
4. [Generate cache plan](#generate-cache-plan)
5. [Generate the driver](#generate-the-driver)
6. [Switch the driver](#switch-the-driver)

### Install isuc CLI

```sh
go install github.com/traP-jp/isuc/cli/isuc@latest
```

### Extractor

#### Static Extractor

<!-- TODO: rewrite for production usage (not need to clone repository) -->

- `--out` represents the destination file of the extracted queries.
- Set to `extracted.sql` by default

```sh
go run cli/*.go extract --out extracted.sql /path/to/your/codebase/dir
isuc extract --out extracted.sql /path/to/your/codebase/dir
```

#### Dynamic Extractor
Expand Down Expand Up @@ -63,10 +68,8 @@ mysql -u "$USER" -p"$PASSWORD" -h "$HOST" -N -e "SHOW TABLES FROM $DATABASE" | w

### Generate Cache Plan

<!-- TODO: rewrite for production usage (not need to clone repository) -->

```sh
go run cli/*.go analyze --sql extracted.sql --schema schema.sql --out isuc.yaml
isuc analyze --sql extracted.sql --schema schema.sql --out isuc.yaml
```

- `--sql` represents extracted queries (via the static/dynamic extractor)
Expand All @@ -78,10 +81,8 @@ go run cli/*.go analyze --sql extracted.sql --schema schema.sql --out isuc.yaml

### Generate the driver

<!-- TODO: rewrite for production usage (not need to clone repository) -->

```sh
go run cli/*.go generate --plan isuc.yaml --schema schema.sql <dist>
isuc generate --plan isuc.yaml --schema schema.sql <dist>
```

- `--plan` represents generated cache plan
Expand All @@ -101,7 +102,6 @@ Rewrite the section of connecting to a database.

## Appendix


### Cache Plan Format

```ts
Expand Down
5 changes: 3 additions & 2 deletions cli/analyzer.go → cli/isuc/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

var analyzeCmd = &cobra.Command{
Use: "analyze",
Long: "Analyze the extracted queries and generate a cache plan",
Use: "analyze",
Short: "Analyze the extracted queries and generate a cache plan",
Long: "Analyze the extracted queries and generate a cache plan",
RunE: func(cmd *cobra.Command, args []string) error {
sqlFile := cmd.Flag("sql").Value.String()
schemasFile := cmd.Flag("schema").Value.String()
Expand Down
1 change: 1 addition & 0 deletions cli/extractor.go → cli/isuc/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

var extractCmd = &cobra.Command{
Use: "extract",
Short: "Extract SQL queries from the codebase",
Long: "Statistically analyze the codebase and extract SQL queries",
Args: cobra.ExactArgs(1),
ValidArgs: []string{"path"},
Expand Down
1 change: 1 addition & 0 deletions cli/generator.go → cli/isuc/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate a driver from the cache plan and table schema",
Long: "Generate a driver from the cache plan and table schema",
Args: cobra.ExactArgs(1),
ValidArgs: []string{"path"},
Expand Down
File renamed without changes.

0 comments on commit 32e146e

Please sign in to comment.