Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

chore: improve UX of forc index plugin commands #1142

Merged
merged 12 commits into from
Aug 1, 2023
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ jobs:

# WASM indexer
forc-index new indexer-test --namespace fuel
cd indexer-test/
cd indexer-test
forc-index build
cd ..
rm -rfv indexer-test

# Native indexer
forc-index new indexer-test --namespace fuel --native
cd indexer-test/
cd indexer-test
forc-index build --native
cd ..
rm -rfv indexer-test
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,15 @@ OPTIONS:
SUBCOMMANDS:
auth Authenticate against an indexer service
build Build an indexer
check Get status checks on all indexer components
check Check for Fuel indexer components
deploy Deploy an indexer to an indexer service
help Print this message or the help of the given subcommand(s)
init Create a new indexer project in the current directory
kill Kill the indexer process. Note that this command will kill any process listening
on the default indexer port or the port specified by the `--port` flag
new Create a new indexer project in a new directory
postgres Fuel Postgres Orchestrator
remove Stop and remove a running indexer
start Standalone binary for the fuel indexer service.
start Standalone binary for the Fuel indexer service
status Check the status of a registered indexer
```

Expand Down
8 changes: 2 additions & 6 deletions docs/src/forc-index/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
Build an indexer.

```bash
forc index build --release
forc index build
```

```text
USAGE:
forc-index build [OPTIONS]

OPTIONS:
-d, --debug Build artifacts with the debug profile.
-h, --help Print help information
--locked Ensure that the Cargo.lock file is up-to-date.
-m, --manifest <MANIFEST> Manifest file name of indexer being built.
--native Building for native execution.
-p, --path <PATH> Path to the indexer project.
--profile <PROFILE> Build with the given profile.
-r, --release Build optimized artifacts with the release profile. [default:
true]
--target <TARGET> Target at which to compile. [default: wasm32-unknown-unknown]
--target-dir <TARGET_DIR> Directory for all generated artifacts and intermediate files.
-v, --verbose Enable verbose output.

```
14 changes: 2 additions & 12 deletions docs/src/forc-index/check.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,23 @@ forc index check

```text
USAGE:
forc-index check [OPTIONS]
forc-index check

OPTIONS:
--grpahql-api-port <GRPAHQL_API_PORT>
Port at which to detect indexer service API is running. [default: 29987]

-h, --help
Print help information

--url <URL>
URL at which to find indexer service. [default: http://localhost:29987]
```

You can expect the command output to look something like this example in which the requisite components are installed but the indexer service is not running:
You can expect the command output to look something like this:

```text
➜ forc index check

❌ Could not connect to indexer service: error sending request for url (http://localhost:29987/api/health): error trying to connect: tcp connect error: Connection refused (os error 61)

+--------+------------------------+----------------------------------------------------------------------------+
| Status | Component | Details |
+--------+------------------------+----------------------------------------------------------------------------+
| ✅ | fuel-indexer binary | Found 'fuel-indexer' at '/Users/me/.fuelup/bin/fuel-indexer' |
+--------+------------------------+----------------------------------------------------------------------------+
| ⛔️ | fuel-indexer service | Failed to detect a locally running fuel-indexer service at Port(29987). |
+--------+------------------------+----------------------------------------------------------------------------+
| ✅ | psql | Found 'psql' at '/usr/local/bin/psql' |
+--------+------------------------+----------------------------------------------------------------------------+
| ✅ | fuel-core | Found 'fuel-core' at '/Users/me/.fuelup/bin/fuel-core' |
Expand Down
7 changes: 2 additions & 5 deletions docs/src/forc-index/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ USAGE:

OPTIONS:
--auth <AUTH> Authentication header value.
-d, --debug Build optimized artifacts with the debug profile.
-h, --help Print help information
--locked Ensure that the Cargo.lock file is up-to-date.
-m, --manifest <MANIFEST> Path to the manifest of indexer project being deployed.
--native Building for native execution.
-p, --path <PATH> Path to the indexer project.
--profile <PROFILE> Build with the given profile.
-r, --release Build optimized artifacts with the release profile. [default:
true]
--remove-data Remove all indexed data when replacing an existing indexer.
--replace-indexer If an indexer with the same UID exists, remove it.
--skip-build Do not build before deploying.
--target <TARGET> Target at which to compile. [default: wasm32-unknown-unknown]
--target-dir <TARGET_DIR> Directory for all generated artifacts and intermediate files.
--url <URL> URL at which to deploy indexer assets. [default:
http://localhost:29987]
http://127.0.0.1:29987]
-v, --verbose Enable verbose logging.
```
23 changes: 0 additions & 23 deletions docs/src/forc-index/init.md

This file was deleted.

17 changes: 17 additions & 0 deletions docs/src/forc-index/kill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `forc index kill`

Kill the indexer process. Note that this command will kill any process listening on the default indexer port or the port specified by the `--port` flag.

```bash
forc index kill --port 29987
```

```text
USAGE:
forc-index kill [OPTIONS]

OPTIONS:
-9 Terminate or kill
-h, --help Print help information
--port <PORT> Port at which to detect indexer service API is running. [default: 29987]
```
9 changes: 4 additions & 5 deletions docs/src/forc-index/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Create a new indexer project in a new directory.

```bash
forc index new --namespace fuel --path /home/fuel/projects
forc index new --namespace fuel /home/fuel/projects/example_indexer
```

```text
USAGE:
forc-index new [OPTIONS] --namespace <NAMESPACE> <PATH>
forc-index new [OPTIONS] <PATH>

ARGS:
<PATH> Path at which to create indexer
Expand All @@ -18,7 +18,6 @@ OPTIONS:
-h, --help Print help information
--name <NAME> Name of indexer.
--namespace <NAMESPACE> Namespace to which indexer belongs.
--native Whether to initialize an indexer with native execution enabled.
-v, --verbose <verbose> Enable verbose output. [default: true]

--native Initialize an indexer with native execution enabled.
-v, --verbose Enable verbose output
```
2 changes: 0 additions & 2 deletions docs/src/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ Take a quick tour.
List indexer components.
`forc index new`
Create a new indexer.
`forc index init`
Create a new indexer in an existing directory.
`forc index start`
Start a local indexer service.
`forc index build`
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel-indexer-lib/src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::path::PathBuf;
#[derive(Debug, Parser, Clone)]
#[clap(
name = "Indexer Service",
about = "Standalone binary for the fuel indexer service.",
about = "Standalone binary for the Fuel indexer service",
version
)]
pub struct IndexerArgs {
Expand Down
1 change: 1 addition & 0 deletions plugins/forc-index/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tokio = { features = ["macros", "rt-multi-thread", "process"], workspace = true
toml = "0.5"
tracing = { workspace = true }
walkdir = "2"
whoami = "1.4"

[[bin]]
name = "forc-index"
Expand Down
8 changes: 0 additions & 8 deletions plugins/forc-index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ A `forc` plugin for basic Fuel Indexer interaction.

## Commands

### `forc index init`

Create a new indexer project at the provided path. If no path is provided the current working directory will be used.

```bash
forc index init --namespace fuel
```

### `forc index new`

Create new indexer project at the provided path.
Expand Down
10 changes: 4 additions & 6 deletions plugins/forc-index/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pub(crate) use crate::commands::{
auth::Command as AuthCommand, build::Command as BuildCommand,
check::Command as CheckCommand, deploy::Command as DeployCommand,
init::Command as InitCommand, kill::Command as KillCommand,
new::Command as NewCommand, remove::Command as RemoveCommand,
start::Command as StartCommand, status::Command as StatusCommand,
kill::Command as KillCommand, new::Command as NewCommand,
remove::Command as RemoveCommand, start::Command as StartCommand,
status::Command as StatusCommand,
};
use clap::{Parser, Subcommand};
use forc_postgres::{
Expand All @@ -23,7 +23,6 @@ pub struct Opt {

#[derive(Subcommand, Debug)]
pub enum ForcIndex {
Init(InitCommand),
New(NewCommand),
Deploy(DeployCommand),
Start(Box<StartCommand>),
Expand All @@ -44,11 +43,10 @@ pub async fn run_cli() -> Result<(), anyhow::Error> {
init_tracing_subscriber(tracing_options);

match opt.command {
ForcIndex::Init(command) => crate::commands::init::exec(command),
ForcIndex::New(command) => crate::commands::new::exec(command),
ForcIndex::Deploy(command) => crate::commands::deploy::exec(command).await,
ForcIndex::Start(command) => crate::commands::start::exec(command).await,
ForcIndex::Check(command) => crate::commands::check::exec(command).await,
ForcIndex::Check(_command) => crate::commands::check::exec().await,
ForcIndex::Remove(command) => crate::commands::remove::exec(command).await,
ForcIndex::Build(command) => crate::commands::build::exec(command),
ForcIndex::Auth(command) => crate::commands::auth::exec(command).await,
Expand Down
25 changes: 5 additions & 20 deletions plugins/forc-index/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{defaults, ops::forc_index_build};
use crate::ops::forc_index_build;
use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;
Expand All @@ -14,22 +14,9 @@ pub struct Command {
#[clap(short, long, help = "Path to the indexer project.")]
pub path: Option<PathBuf>,

/// Target at which to compile.
#[clap(long, default_value = defaults::INDEXER_TARGET, help = "Target at which to compile.")]
pub target: String,

/// Build optimized artifacts with the release profile.
#[clap(
short,
long,
help = "Build optimized artifacts with the release profile.",
default_value = defaults::BUILD_RELEASE_PROFILE,
)]
pub release: String,

/// Build with the given profile.
#[clap(long, help = "Build with the given profile.")]
pub profile: Option<String>,
/// Build optimized artifacts with the debug profile.
#[clap(short, long, help = "Build artifacts with the debug profile.")]
pub debug: bool,

/// Ensure that the Cargo.lock file is up-to-date.
#[clap(long, help = "Ensure that the Cargo.lock file is up-to-date.")]
Expand All @@ -56,9 +43,7 @@ impl Default for Command {
Command {
manifest: Some(String::new()),
path: None,
target: defaults::WASM_TARGET.to_string(),
release: true.to_string(),
profile: Some("release".to_string()),
debug: false,
verbose: false,
locked: false,
native: false,
Expand Down
20 changes: 7 additions & 13 deletions plugins/forc-index/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
use crate::{defaults, ops::forc_index_check};
use crate::ops::forc_index_check;
use anyhow::Result;
use clap::Parser;

/// Get status checks on all indexer components.
// Command has to be created in order for the help
// message to be shown in the primary help output
/// Check for Fuel indexer components
#[derive(Debug, Parser)]
pub struct Command {
/// URL at which to find indexer service.
#[clap(long, default_value = defaults::INDEXER_SERVICE_HOST, help = "URL at which to find indexer service.")]
pub url: String,
pub struct Command {}

/// Port at which to detect indexer service API is running.
#[clap(long, default_value = defaults::WEB_API_PORT, help = "Port at which to detect indexer service API is running.")]
pub graphql_api_port: String,
}

pub async fn exec(command: Command) -> Result<()> {
forc_index_check::init(command).await
pub async fn exec() -> Result<()> {
forc_index_check::init().await
}
17 changes: 3 additions & 14 deletions plugins/forc-index/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,13 @@ pub struct Command {
#[clap(long, help = "Authentication header value.")]
pub auth: Option<String>,

/// Target at which to compile.
#[clap(long, default_value = defaults::INDEXER_TARGET, help = "Target at which to compile.")]
pub target: String,

/// Build optimized artifacts with the release profile.
#[clap(
short,
long,
help = "Build optimized artifacts with the release profile.",
default_value = defaults::BUILD_RELEASE_PROFILE,
help = "Build optimized artifacts with the debug profile."
)]
pub release: String,

/// Build with the given profile.
#[clap(long, help = "Build with the given profile.")]
pub profile: Option<String>,
pub debug: bool,

/// Ensure that the Cargo.lock file is up-to-date.
#[clap(long, help = "Ensure that the Cargo.lock file is up-to-date.")]
Expand Down Expand Up @@ -85,9 +76,7 @@ impl Default for Command {
manifest: Some(String::new()),
path: None,
auth: Some("".to_string()),
target: defaults::WASM_TARGET.to_string(),
release: true.to_string(),
profile: Some("release".to_string()),
debug: false,
verbose: false,
locked: false,
native: false,
Expand Down
Loading
Loading