feat: add version subcommand for versioning grammars

This commit is contained in:
Amaan Qureshi 2024-10-19 02:08:57 +00:00 committed by GitHub
parent c03977a87e
commit 40606dd632
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 310 additions and 6 deletions

View file

@ -12,7 +12,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm, FuzzySelect, Input};
use glob::glob;
use heck::ToUpperCamelCase;
use regex::Regex;
use semver::Version;
use semver::Version as SemverVersion;
use tree_sitter::{ffi, Parser, Point};
use tree_sitter_cli::{
fuzz::{
@ -25,7 +25,7 @@ use tree_sitter_cli::{
parse::{self, ParseFileOptions, ParseOutput, ParseTheme},
playground, query, tags,
test::{self, TestOptions},
test_highlight, test_tags, util, wasm,
test_highlight, test_tags, util, version, wasm,
};
use tree_sitter_config::Config;
use tree_sitter_highlight::Highlighter;
@ -46,6 +46,7 @@ enum Commands {
Build(Build),
Parse(Parse),
Test(Test),
Version(Version),
Fuzz(Fuzz),
Query(Query),
Highlight(Highlight),
@ -279,6 +280,15 @@ struct Test {
pub overview_only: bool,
}
#[derive(Args)]
#[command(alias = "publish")]
/// Increment the version of a grammar
struct Version {
#[arg(num_args = 1)]
/// The version to bump to
pub version: SemverVersion,
}
#[derive(Args)]
#[command(about = "Fuzz a parser", alias = "f")]
struct Fuzz {
@ -555,9 +565,9 @@ impl Init {
};
let initial_version = || {
Input::<Version>::with_theme(&ColorfulTheme::default())
Input::<SemverVersion>::with_theme(&ColorfulTheme::default())
.with_prompt("Version")
.default(Version::new(0, 1, 0))
.default(SemverVersion::new(0, 1, 0))
.interact_text()
};
@ -1041,6 +1051,12 @@ impl Test {
}
}
impl Version {
fn run(self, current_dir: PathBuf) -> Result<()> {
version::Version::new(self.version.to_string(), current_dir).run()
}
}
impl Fuzz {
fn run(self, mut loader: loader::Loader, current_dir: &Path) -> Result<()> {
loader.sanitize_build(true);
@ -1346,6 +1362,7 @@ fn run() -> Result<()> {
Commands::Build(build_options) => build_options.run(loader, &current_dir)?,
Commands::Parse(parse_options) => parse_options.run(loader, &current_dir)?,
Commands::Test(test_options) => test_options.run(loader, &current_dir)?,
Commands::Version(version_options) => version_options.run(current_dir)?,
Commands::Fuzz(fuzz_options) => fuzz_options.run(loader, &current_dir)?,
Commands::Query(query_options) => query_options.run(loader, &current_dir)?,
Commands::Highlight(highlight_options) => highlight_options.run(loader)?,