Skip to content

Commit

Permalink
Fix broken forc command docs (#6424)
Browse files Browse the repository at this point in the history
## Description
I noticed that the command section for forc in the documentation was
only showing headings and no information about the commands themselves.
See below.

![Screenshot 2024-08-19 at 10 47
48 AM](https://github.com/user-attachments/assets/ee5c00d3-97f2-445a-b1c7-203144bf2d13)

This was due to back ticks being placed around the heading in #5369.
I've removed these ticks and added the commands to the list of accepted
words.

Also there were a lot of commands being missed due to their no longer
being subcommands, this logic has been updated and all the forc commands
are now being parsed.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
JoshuaBatty authored Aug 19, 2024
1 parent 749e897 commit 7dc3e2d
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 63 deletions.
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
11 changes: 7 additions & 4 deletions scripts/mdbook-forc-documenter/src/bin/mdbook-forc-documenter.rs
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

0 comments on commit 7dc3e2d

Please sign in to comment.