Remove options from README

This commit is contained in:
Martin Fischer 2023-02-15 21:40:12 +01:00 committed by Charlie Marsh
parent b0d72c47b4
commit d658bfc024
5 changed files with 10 additions and 1997 deletions

1969
README.md

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@
use anyhow::Result; use anyhow::Result;
use crate::{generate_cli_help, generate_docs, generate_json_schema, generate_options}; use crate::{generate_cli_help, generate_docs, generate_json_schema};
#[derive(clap::Args)] #[derive(clap::Args)]
pub struct Args { pub struct Args {
@ -18,9 +18,6 @@ pub fn main(args: &Args) -> Result<()> {
generate_json_schema::main(&generate_json_schema::Args { generate_json_schema::main(&generate_json_schema::Args {
dry_run: args.dry_run, dry_run: args.dry_run,
})?; })?;
generate_options::main(&generate_options::Args {
dry_run: args.dry_run,
})?;
generate_cli_help::main(&generate_cli_help::Args { generate_cli_help::main(&generate_cli_help::Args {
dry_run: args.dry_run, dry_run: args.dry_run,
})?; })?;

View file

@ -1,23 +1,8 @@
//! Generate a Markdown-compatible listing of configuration options. //! Generate a Markdown-compatible listing of configuration options.
#![allow(clippy::print_stdout, clippy::print_stderr)]
use anyhow::Result;
use itertools::Itertools; use itertools::Itertools;
use ruff::settings::options::Options; use ruff::settings::options::Options;
use ruff::settings::options_base::{ConfigurationOptions, OptionEntry, OptionField}; use ruff::settings::options_base::{ConfigurationOptions, OptionEntry, OptionField};
use crate::utils::replace_readme_section;
const BEGIN_PRAGMA: &str = "<!-- Begin auto-generated options sections. -->\n";
const END_PRAGMA: &str = "<!-- End auto-generated options sections. -->";
#[derive(clap::Args)]
pub struct Args {
/// Write the generated table to stdout (rather than to `README.md`).
#[arg(long)]
pub(crate) dry_run: bool,
}
fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name: Option<&str>) { fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name: Option<&str>) {
output.push_str(&format!("#### [`{0}`](#{0})\n", name)); output.push_str(&format!("#### [`{0}`](#{0})\n", name));
output.push('\n'); output.push('\n');
@ -39,7 +24,7 @@ fn emit_field(output: &mut String, name: &str, field: &OptionField, group_name:
output.push('\n'); output.push('\n');
} }
pub fn main(args: &Args) -> Result<()> { pub fn generate() -> String {
let mut output: String = "### Top-level\n\n".into(); let mut output: String = "### Top-level\n\n".into();
let mut sorted_options = Options::get_available_options(); let mut sorted_options = Options::get_available_options();
@ -64,11 +49,5 @@ pub fn main(args: &Args) -> Result<()> {
} }
} }
if args.dry_run { output
print!("{output}");
} else {
replace_readme_section(&output, BEGIN_PRAGMA, END_PRAGMA)?;
}
Ok(())
} }

View file

@ -36,7 +36,7 @@ enum Command {
/// Generate a Markdown-compatible table of supported lint rules. /// Generate a Markdown-compatible table of supported lint rules.
GenerateRulesTable, GenerateRulesTable,
/// Generate a Markdown-compatible listing of configuration options. /// Generate a Markdown-compatible listing of configuration options.
GenerateOptions(generate_options::Args), GenerateOptions,
/// Generate CLI help. /// Generate CLI help.
GenerateCliHelp(generate_cli_help::Args), GenerateCliHelp(generate_cli_help::Args),
/// Generate Markdown docs. /// Generate Markdown docs.
@ -58,7 +58,7 @@ fn main() -> Result<()> {
Command::GenerateAll(args) => generate_all::main(args)?, Command::GenerateAll(args) => generate_all::main(args)?,
Command::GenerateJSONSchema(args) => generate_json_schema::main(args)?, Command::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
Command::GenerateRulesTable => println!("{}", generate_rules_table::generate()), Command::GenerateRulesTable => println!("{}", generate_rules_table::generate()),
Command::GenerateOptions(args) => generate_options::main(args)?, Command::GenerateOptions => println!("{}", generate_options::generate()),
Command::GenerateCliHelp(args) => generate_cli_help::main(args)?, Command::GenerateCliHelp(args) => generate_cli_help::main(args)?,
Command::GenerateDocs(args) => generate_docs::main(args)?, Command::GenerateDocs(args) => generate_docs::main(args)?,
Command::PrintAST(args) => print_ast::main(args)?, Command::PrintAST(args) => print_ast::main(args)?,

View file

@ -49,6 +49,10 @@ def main() -> None:
# Split the README.md into sections. # Split the README.md into sections.
for title, filename in SECTIONS: for title, filename in SECTIONS:
with Path(f"docs/{filename}").open("w+") as f: with Path(f"docs/{filename}").open("w+") as f:
if filename == "settings.md":
f.write(subprocess.check_output(["cargo", "dev", "generate-options"], encoding="utf-8"))
continue
block = content.split(f"<!-- Begin section: {title} -->") block = content.split(f"<!-- Begin section: {title} -->")
if len(block) != 2: if len(block) != 2:
msg = f"Section {title} not found in README.md" msg = f"Section {title} not found in README.md"