refactor: remove url dependency
This commit is contained in:
parent
6a28a62369
commit
46ea65c89b
10 changed files with 29 additions and 65 deletions
|
|
@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize};
|
|||
use serde_json::{Map, Value};
|
||||
use tree_sitter_generate::write_file;
|
||||
use tree_sitter_loader::{Author, Bindings, Grammar, Links, Metadata, PathsJSON, TreeSitterJSON};
|
||||
use url::Url;
|
||||
|
||||
const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const CLI_VERSION_PLACEHOLDER: &str = "CLI_VERSION";
|
||||
|
|
@ -110,9 +109,9 @@ pub struct JsonConfigOpts {
|
|||
pub title: String,
|
||||
pub description: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub repository: Option<Url>,
|
||||
pub repository: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub funding: Option<Url>,
|
||||
pub funding: Option<String>,
|
||||
pub scope: String,
|
||||
pub file_types: Vec<String>,
|
||||
pub version: Version,
|
||||
|
|
@ -121,7 +120,7 @@ pub struct JsonConfigOpts {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub email: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<Url>,
|
||||
pub url: Option<String>,
|
||||
pub bindings: Bindings,
|
||||
}
|
||||
|
||||
|
|
@ -158,11 +157,7 @@ impl JsonConfigOpts {
|
|||
}]),
|
||||
links: Some(Links {
|
||||
repository: self.repository.unwrap_or_else(|| {
|
||||
Url::parse(&format!(
|
||||
"https://github.com/tree-sitter/tree-sitter-{}",
|
||||
self.name
|
||||
))
|
||||
.expect("Failed to parse default repository URL")
|
||||
format!("https://github.com/tree-sitter/tree-sitter-{}", self.name)
|
||||
}),
|
||||
funding: self.funding,
|
||||
}),
|
||||
|
|
@ -277,7 +272,7 @@ pub fn generate_grammar_files(
|
|||
.metadata
|
||||
.links
|
||||
.as_ref()
|
||||
.and_then(|l| l.funding.as_ref().map(|f| f.as_str())),
|
||||
.and_then(|l| l.funding.as_deref()),
|
||||
version: &tree_sitter_config.metadata.version,
|
||||
camel_parser_name: &camel_name,
|
||||
title_parser_name: &title_name,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ use tree_sitter_config::Config;
|
|||
use tree_sitter_highlight::Highlighter;
|
||||
use tree_sitter_loader::{self as loader, Bindings, TreeSitterJSON};
|
||||
use tree_sitter_tags::TagsContext;
|
||||
use url::Url;
|
||||
|
||||
const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
const BUILD_SHA: Option<&'static str> = option_env!("BUILD_SHA");
|
||||
|
|
@ -651,15 +650,10 @@ impl Init {
|
|||
};
|
||||
|
||||
let repository = |name: &str| {
|
||||
Input::<Url>::with_theme(&ColorfulTheme::default())
|
||||
Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Repository URL")
|
||||
.allow_empty(true)
|
||||
.default(
|
||||
Url::parse(&format!(
|
||||
"https://github.com/tree-sitter/tree-sitter-{name}"
|
||||
))
|
||||
.expect("Failed to parse default repository URL"),
|
||||
)
|
||||
.default(format!("https://github.com/tree-sitter/tree-sitter-{name}"))
|
||||
.show_default(false)
|
||||
.interact_text()
|
||||
};
|
||||
|
|
@ -668,18 +662,8 @@ impl Init {
|
|||
Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Funding URL")
|
||||
.allow_empty(true)
|
||||
.validate_with(|input: &String| {
|
||||
if input.trim().is_empty()
|
||||
|| Url::parse(input)
|
||||
.is_ok_and(|u| u.scheme() == "http" || u.scheme() == "https")
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err("The URL must start with 'http://' or 'https://'")
|
||||
}
|
||||
})
|
||||
.interact_text()
|
||||
.map(|e| (!e.trim().is_empty()).then(|| Url::parse(&e).unwrap()))
|
||||
.map(|e| Some(e.trim().to_string()))
|
||||
};
|
||||
|
||||
let scope = |name: &str| {
|
||||
|
|
@ -746,15 +730,8 @@ impl Init {
|
|||
Input::<String>::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Author URL")
|
||||
.allow_empty(true)
|
||||
.validate_with(|input: &String| -> Result<(), &str> {
|
||||
if input.trim().is_empty() || Url::parse(input).is_ok() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("This is not a valid URL")
|
||||
}
|
||||
})
|
||||
.interact_text()
|
||||
.map(|e| (!e.trim().is_empty()).then(|| Url::parse(&e).unwrap()))
|
||||
.map(|e| Some(e.trim().to_string()))
|
||||
};
|
||||
|
||||
let bindings = || {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue