Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken forc command docs #6424

Merged
merged 7 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion docs/book/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ASM
IDE
IDEs
LSP
lsp
namespace
ALU
APIs
Expand Down Expand Up @@ -216,4 +217,14 @@ underflows
Codec
bool
str
multisig
multisig
addr
addr2line
contract-id
init
parse-bytecode
predicate-root
forc-client
crypto
doc
fmt
48 changes: 24 additions & 24 deletions docs/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,28 @@
- [Workspaces](./forc/workspaces.md)
- [Dependencies](./forc/dependencies.md)
- [Commands](./forc/commands/index.md)
- [`forc addr2line`](./forc/commands/forc_addr2line.md)
- [`forc build`](./forc/commands/forc_build.md)
- [`forc check`](./forc/commands/forc_check.md)
- [`forc clean`](./forc/commands/forc_clean.md)
- [`forc completions`](./forc/commands/forc_completions.md)
- [`forc contract-id`](./forc/commands/forc_contract-id.md)
- [`forc init`](./forc/commands/forc_init.md)
- [`forc new`](./forc/commands/forc_new.md)
- [`forc parse-bytecode`](./forc/commands/forc_parse-bytecode.md)
- [`forc plugins`](./forc/commands/forc_plugins.md)
- [`forc predicate-root`](./forc/commands/forc_predicate-root.md)
- [`forc test`](./forc/commands/forc_test.md)
- [`forc update`](./forc/commands/forc_update.md)
- [`forc template`](./forc/commands/forc_template.md)
- [forc addr2line](./forc/commands/forc_addr2line.md)
- [forc build](./forc/commands/forc_build.md)
- [forc check](./forc/commands/forc_check.md)
- [forc clean](./forc/commands/forc_clean.md)
- [forc completions](./forc/commands/forc_completions.md)
- [forc contract-id](./forc/commands/forc_contract-id.md)
- [forc init](./forc/commands/forc_init.md)
- [forc new](./forc/commands/forc_new.md)
- [forc parse-bytecode](./forc/commands/forc_parse-bytecode.md)
- [forc plugins](./forc/commands/forc_plugins.md)
- [forc predicate-root](./forc/commands/forc_predicate-root.md)
- [forc test](./forc/commands/forc_test.md)
- [forc update](./forc/commands/forc_update.md)
- [forc template](./forc/commands/forc_template.md)
- [Plugins](./forc/plugins/index.md)
- [`forc client`](./forc/plugins/forc_client/index.md)
- [`forc deploy`](./forc/plugins/forc_client/forc_deploy.md)
- [`forc run`](./forc/plugins/forc_client/forc_run.md)
- [`forc submit`](./forc/plugins/forc_client/forc_submit.md)
- [`forc crypto`](./forc/plugins/forc_crypto.md)
- [`forc debug`](./forc/plugins/forc_debug.md)
- [`forc doc`](./forc/plugins/forc_doc.md)
- [`forc explore`](./forc/plugins/forc_explore.md)
- [`forc fmt`](./forc/plugins/forc_fmt.md)
- [`forc lsp`](./forc/plugins/forc_lsp.md)
- [forc client](./forc/plugins/forc_client/index.md)
- [forc deploy](./forc/plugins/forc_client/forc_deploy.md)
- [forc run](./forc/plugins/forc_client/forc_run.md)
- [forc submit](./forc/plugins/forc_client/forc_submit.md)
- [forc crypto](./forc/plugins/forc_crypto.md)
- [forc debug](./forc/plugins/forc_debug.md)
- [forc doc](./forc/plugins/forc_doc.md)
- [forc explore](./forc/plugins/forc_explore.md)
- [forc fmt](./forc/plugins/forc_fmt.md)
- [forc lsp](./forc/plugins/forc_lsp.md)
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_addr2line.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc addr2line`
# forc addr2line
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_build.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc build`
# forc build
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_check.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc check`
# forc check
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_clean.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc clean`
# forc clean
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_completions.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc completions`
# forc completions
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_contract-id.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc contract-id`
# forc contract-id
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_init.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc init`
# forc init
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_new.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc new`
# forc new
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_parse-bytecode.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc parse-bytecode`
# forc parse-bytecode
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_plugins.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc plugins`
# forc plugins
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_predicate-root.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc predicate-root`
# forc predicate-root
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_template.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc template`
# forc template
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_test.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc test`
# forc test
2 changes: 1 addition & 1 deletion docs/book/src/forc/commands/forc_update.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc update`
# forc update
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_client/forc_deploy.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc deploy`
# forc deploy
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_client/forc_run.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc run`
# forc run
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_client/forc_submit.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc submit`
# forc submit
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_client/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `forc-client`
# forc-client

The forc plugin for interacting with a Fuel node.

Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_crypto.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc crypto`
# forc crypto
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_doc.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc doc`
# forc doc
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_explore.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc explore`
# forc explore
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_fmt.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc fmt`
# forc fmt
2 changes: 1 addition & 1 deletion docs/book/src/forc/plugins/forc_lsp.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `forc lsp`
# forc lsp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use clap::{Arg, ArgMatches, Command};
use mdbook::errors::Error;
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
use mdbook_forc_documenter::ForcDocumenter;
use semver::{Version, VersionReq};
use std::io;
use std::process;

use mdbook_forc_documenter::ForcDocumenter;

pub fn make_app() -> Command {
Command::new("forc-documenter")
.about("A mdbook preprocessor which documents Forc commands")
.subcommand(
Command::new("supports")
.arg(Arg::new("renderer").required(true))
.arg(
Arg::new("renderer")
.required(true)
.value_parser(clap::value_parser!(String)),
)
.about("Check whether a renderer is supported by this preprocessor"),
)
}
Expand Down Expand Up @@ -53,7 +56,7 @@ fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
}

fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! {
let renderer: &Option<&str> = sub_args.get_one("renderer").expect("Required argument");
let renderer = sub_args.get_one::<String>("renderer").map(String::as_str);
let supported = renderer.map(|r| pre.supports_renderer(r)).unwrap_or(false);

// Signal whether the renderer is supported by exiting with 1 or 0.
Expand Down
28 changes: 17 additions & 11 deletions scripts/mdbook-forc-documenter/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use crate::formatter::{format_header_line, format_line};
use anyhow::{anyhow, Result};
use std::collections::HashMap;
use std::ffi::OsString;
use std::process;
use std::{collections::HashMap, ffi::OsString, process};

pub fn possible_forc_commands() -> Vec<String> {
let mut possible_commands = Vec::new();
let output = process::Command::new("forc")
.arg("--help")
.output()
Expand All @@ -14,18 +11,27 @@ pub fn possible_forc_commands() -> Vec<String> {
let output_str = String::from_utf8_lossy(&output.stdout);
let lines = output_str.lines();

let mut has_parsed_subcommand_header = false;
let mut possible_commands = Vec::new();
let mut in_commands_section = false;

for line in lines {
if has_parsed_subcommand_header {
let (command, _) = line.trim().split_once(' ').unwrap_or(("", ""));
possible_commands.push(command.to_string());
if line.trim() == "Commands:" {
// Start of commands section
in_commands_section = true;
continue;
}
if line == "SUBCOMMANDS:" {
has_parsed_subcommand_header = true;

if in_commands_section {
if line.trim().is_empty() || line.trim().starts_with("Options:") {
// End of commands section
break;
}
// Extract command name (first word of the line)
if let Some(command) = line.split_whitespace().next() {
possible_commands.push(command.to_string());
}
}
}

possible_commands
}

Expand Down
Loading