Fix publish script (#825)

This commit is contained in:
Denis Isidoro 2023-04-09 10:08:42 -03:00 committed by GitHub
parent e3920552ca
commit f8192a468e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 50 additions and 59 deletions

View File

@ -51,6 +51,9 @@ jobs:
- name: Get the version - name: Get the version
id: get_version id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Install target
id: installtarget
run: rustup target add ${{ matrix.target }}
- name: Upload binaries to release - name: Upload binaries to release
uses: svenstaro/upload-release-action@v1-release uses: svenstaro/upload-release-action@v1-release
with: with:

View File

@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "1.68.2" channel = "1.67.0"
components = [ "rustfmt", "clippy" ] components = [ "rustfmt", "clippy" ]

View File

@ -7,9 +7,8 @@ fn map_line(line: &str) -> String {
fn as_lines(query: &str, markdown: &str) -> Vec<String> { fn as_lines(query: &str, markdown: &str) -> Vec<String> {
format!( format!(
"% {}, cheat.sh "% {query}, cheat.sh
{}", {markdown}"
query, markdown
) )
.lines() .lines()
.map(map_line) .map(map_line)
@ -17,7 +16,7 @@ fn as_lines(query: &str, markdown: &str) -> Vec<String> {
} }
pub fn call(query: &str) -> Result<Vec<String>> { pub fn call(query: &str) -> Result<Vec<String>> {
let args = ["-qO-", &format!("cheat.sh/{}", query)]; let args = ["-qO-", &format!("cheat.sh/{query}")];
let child = Command::new("wget") let child = Command::new("wget")
.args(args) .args(args)

View File

@ -18,10 +18,10 @@ fn convert_tldr_vars(line: &str) -> String {
let mut new_var = NON_VAR_CHARS_REGEX.replace_all(var, "_").to_string(); let mut new_var = NON_VAR_CHARS_REGEX.replace_all(var, "_").to_string();
if let Some(c) = new_var.chars().next() { if let Some(c) = new_var.chars().next() {
if c.to_string().parse::<u8>().is_ok() { if c.to_string().parse::<u8>().is_ok() {
new_var = format!("example_{}", new_var); new_var = format!("example_{new_var}");
} }
} }
let bracketed_var = format!("<{}>", new_var); let bracketed_var = format!("<{new_var}>");
new_line = new_line.replace(braced_var, &bracketed_var); new_line = new_line.replace(braced_var, &bracketed_var);
} }
new_line new_line
@ -42,9 +42,8 @@ fn convert_tldr(line: &str) -> String {
fn markdown_lines(query: &str, markdown: &str) -> Vec<String> { fn markdown_lines(query: &str, markdown: &str) -> Vec<String> {
format!( format!(
"% {}, tldr "% {query}, tldr
{}", {markdown}"
query, markdown
) )
.lines() .lines()
.map(convert_tldr) .map(convert_tldr)
@ -70,9 +69,8 @@ Make sure tldr is correctly installed.
Refer to https://github.com/tldr-pages/tldr for more info. Refer to https://github.com/tldr-pages/tldr for more info.
Note: Note:
{} {VERSION_DISCLAIMER}
", "
VERSION_DISCLAIMER
); );
return Err(anyhow!(msg)); return Err(anyhow!(msg));
} }

View File

@ -77,7 +77,7 @@ fn prompt_finder(
name = variable_name, name = variable_name,
extra = extra_preview extra = extra_preview
.clone() .clone()
.map(|e| format!(" echo; {}", e)) .map(|e| format!(" echo; {e}"))
.unwrap_or_default(), .unwrap_or_default(),
) )
} else { } else {
@ -93,7 +93,7 @@ fn prompt_finder(
name = variable_name, name = variable_name,
extra = extra_preview extra = extra_preview
.clone() .clone()
.map(|e| format!(" echo; {}", e)) .map(|e| format!(" echo; {e}"))
.unwrap_or_default(), .unwrap_or_default(),
eof = EOF, eof = EOF,
) )
@ -105,9 +105,9 @@ fn prompt_finder(
..initial_opts.clone().unwrap_or_else(FinderOpts::var_default) ..initial_opts.clone().unwrap_or_else(FinderOpts::var_default)
}; };
opts.query = env_var::get(format!("{}__query", variable_name)).ok(); opts.query = env_var::get(format!("{variable_name}__query")).ok();
if let Ok(f) = env_var::get(format!("{}__best", variable_name)) { if let Ok(f) = env_var::get(format!("{variable_name}__best")) {
opts.filter = Some(f); opts.filter = Some(f);
opts.suggestion_type = SuggestionType::SingleSelection; opts.suggestion_type = SuggestionType::SingleSelection;
} }
@ -229,7 +229,7 @@ pub fn act(
match CONFIG.action() { match CONFIG.action() {
Action::Print => { Action::Print => {
println!("{}", interpolated_snippet); println!("{interpolated_snippet}");
} }
Action::Execute => match key { Action::Execute => match key {
"ctrl-y" => { "ctrl-y" => {

View File

@ -11,7 +11,7 @@ pub fn last_command() -> Result<()> {
for p in parts { for p in parts {
for (pattern, escaped) in replacements.clone() { for (pattern, escaped) in replacements.clone() {
if p.contains(pattern) && p != pattern && p != format!("{}{}", pattern, pattern) { if p.contains(pattern) && p != pattern && p != format!("{pattern}{pattern}") {
let replacement = p.replace(pattern, escaped); let replacement = p.replace(pattern, escaped);
text = text.replace(&p, &replacement); text = text.replace(&p, &replacement);
} }

View File

@ -30,7 +30,7 @@ impl Runnable for Input {
println!( println!(
"{comment} {tags} \n{snippet}", "{comment} {tags} \n{snippet}",
comment = style(comment).with(CONFIG.comment_color()), comment = style(comment).with(CONFIG.comment_color()),
tags = style(format!("[{}]", tags)).with(CONFIG.tag_color()), tags = style(format!("[{tags}]")).with(CONFIG.tag_color()),
snippet = style(deser::fix_newlines(snippet)).with(CONFIG.snippet_color()), snippet = style(deser::fix_newlines(snippet)).with(CONFIG.snippet_color()),
); );

View File

@ -42,10 +42,10 @@ impl Runnable for Input {
println!( println!(
"{comment} {tags}", "{comment} {tags}",
comment = style(comment).with(CONFIG.comment_color()), comment = style(comment).with(CONFIG.comment_color()),
tags = style(format!("[{}]", tags)).with(CONFIG.tag_color()), tags = style(format!("[{tags}]")).with(CONFIG.tag_color()),
); );
let bracketed_current_variable = format!("<{}>", variable); let bracketed_current_variable = format!("<{variable}>");
let bracketed_variables: Vec<&str> = { let bracketed_variables: Vec<&str> = {
if snippet.contains(&bracketed_current_variable) { if snippet.contains(&bracketed_current_variable) {
@ -102,7 +102,7 @@ impl Runnable for Input {
} }
println!("{snippet}", snippet = deser::fix_newlines(&colored_snippet)); println!("{snippet}", snippet = deser::fix_newlines(&colored_snippet));
println!("{variables}", variables = variables); println!("{variables}");
process::exit(0) process::exit(0)
} }

View File

@ -41,13 +41,13 @@ pub fn main(uri: String) -> Result<()> {
eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str); eprintln!("Cloning {} into {}...\n", &actual_uri, &tmp_path_str);
git::shallow_clone(actual_uri.as_str(), tmp_path_str) git::shallow_clone(actual_uri.as_str(), tmp_path_str)
.with_context(|| format!("Failed to clone `{}`", actual_uri))?; .with_context(|| format!("Failed to clone `{actual_uri}`"))?;
let all_files = filesystem::all_cheat_files(&tmp_pathbuf).join("\n"); let all_files = filesystem::all_cheat_files(&tmp_pathbuf).join("\n");
let opts = FinderOpts { let opts = FinderOpts {
suggestion_type: SuggestionType::MultipleSelections, suggestion_type: SuggestionType::MultipleSelections,
preview: Some(format!("cat '{}/{{}}'", tmp_path_str)), preview: Some(format!("cat '{tmp_path_str}/{{}}'")),
header: Some("Select the cheatsheets you want to import with <TAB> then hit <Enter>\nUse Ctrl-R for (de)selecting all".to_string()), header: Some("Select the cheatsheets you want to import with <TAB> then hit <Enter>\nUse Ctrl-R for (de)selecting all".to_string()),
preview_window: Some("right:30%".to_string()), preview_window: Some("right:30%".to_string()),
..Default::default() ..Default::default()
@ -69,7 +69,7 @@ pub fn main(uri: String) -> Result<()> {
let to_folder = { let to_folder = {
let mut p = cheat_pathbuf; let mut p = cheat_pathbuf;
p.push(format!("{}__{}", user, repo)); p.push(format!("{user}__{repo}"));
p p
}; };

View File

@ -21,7 +21,7 @@ pub fn main() -> Result<String> {
let (repo_url, _, _) = git::meta("denisidoro/cheats"); let (repo_url, _, _) = git::meta("denisidoro/cheats");
git::shallow_clone(repo_url.as_str(), repo_path_str) git::shallow_clone(repo_url.as_str(), repo_path_str)
.with_context(|| format!("Failed to clone `{}`", repo_url))?; .with_context(|| format!("Failed to clone `{repo_url}`"))?;
let feature_repos_file = { let feature_repos_file = {
let mut p = repo_pathbuf.clone(); let mut p = repo_pathbuf.clone();

View File

@ -27,13 +27,13 @@ impl Runnable for Input {
match &self.cmd { match &self.cmd {
RepoCommand::Add { uri } => { RepoCommand::Add { uri } => {
add::main(uri.clone()) add::main(uri.clone())
.with_context(|| format!("Failed to import cheatsheets from `{}`", uri))?; .with_context(|| format!("Failed to import cheatsheets from `{uri}`"))?;
commands::core::main() commands::core::main()
} }
RepoCommand::Browse => { RepoCommand::Browse => {
let repo = browse::main().context("Failed to browse featured cheatsheets")?; let repo = browse::main().context("Failed to browse featured cheatsheets")?;
add::main(repo.clone()) add::main(repo.clone())
.with_context(|| format!("Failed to import cheatsheets from `{}`", repo))?; .with_context(|| format!("Failed to import cheatsheets from `{repo}`"))?;
commands::core::main() commands::core::main()
} }
} }

View File

@ -36,7 +36,7 @@ impl Runnable for Input {
Shell::Elvish => include_str!("../../shell/navi.plugin.elv"), Shell::Elvish => include_str!("../../shell/navi.plugin.elv"),
}; };
println!("{}", content); println!("{content}");
Ok(()) Ok(())
} }

View File

@ -23,14 +23,11 @@ _copy() {
.arg( .arg(
format!( format!(
r#"{cmd} r#"{cmd}
read -r -d '' x <<'{eof}' read -r -d '' x <<'{EOF}'
{text} {text}
{eof} {EOF}
echo -n "$x" | _copy"#, echo -n "$x" | _copy"#,
cmd = cmd,
text = text,
eof = EOF,
) )
.as_str(), .as_str(),
) )

View File

@ -16,7 +16,7 @@ pub fn meta(uri: &str) -> (String, String, String) {
let actual_uri = if uri.contains("://") || uri.contains('@') { let actual_uri = if uri.contains("://") || uri.contains('@') {
uri.to_string() uri.to_string()
} else { } else {
format!("https://github.com/{}", uri) format!("https://github.com/{uri}")
}; };
let uri_to_split = actual_uri.replace(':', "/"); let uri_to_split = actual_uri.replace(':', "/");

View File

@ -46,7 +46,7 @@ pub fn width() -> u16 {
} }
pub fn parse_ansi(ansi: &str) -> Option<style::Color> { pub fn parse_ansi(ansi: &str) -> Option<style::Color> {
style::Color::parse_ansi(&format!("5;{}", ansi)) style::Color::parse_ansi(&format!("5;{ansi}"))
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View File

@ -26,14 +26,11 @@ _open_url() {
let cmd = format!( let cmd = format!(
r#"{code} r#"{code}
read -r -d '' url <<'{eof}' read -r -d '' url <<'{EOF}'
{url} {url}
{eof} {EOF}
_open_url "$url""#, _open_url "$url""#,
code = code,
url = url,
eof = EOF,
); );
shell::out() shell::out()
.arg(cmd.as_str()) .arg(cmd.as_str())

View File

@ -22,7 +22,7 @@ impl Config {
pub fn new() -> Self { pub fn new() -> Self {
let env = EnvConfig::new(); let env = EnvConfig::new();
let yaml = YamlConfig::get(&env).unwrap_or_else(|e| { let yaml = YamlConfig::get(&env).unwrap_or_else(|e| {
eprintln!("Error parsing config file: {}", e); eprintln!("Error parsing config file: {e}");
eprintln!("Fallbacking to default one..."); eprintln!("Fallbacking to default one...");
eprintln!(); eprintln!();
YamlConfig::default() YamlConfig::default()

View File

@ -21,7 +21,7 @@ where
{ {
let s: String = Deserialize::deserialize(deserializer)?; let s: String = Deserialize::deserialize(deserializer)?;
TerminalColor::try_from(s.as_str()) TerminalColor::try_from(s.as_str())
.map_err(|_| de::Error::custom(format!("Failed to deserialize color: {}", s))) .map_err(|_| de::Error::custom(format!("Failed to deserialize color: {s}")))
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -55,7 +55,7 @@ where
{ {
let s: String = Deserialize::deserialize(deserializer)?; let s: String = Deserialize::deserialize(deserializer)?;
FinderChoice::from_str(s.to_lowercase().as_str()) FinderChoice::from_str(s.to_lowercase().as_str())
.map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {}", s))) .map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {s}")))
} }
#[derive(Deserialize, Default)] #[derive(Deserialize, Default)]

View File

@ -31,7 +31,7 @@ pub fn must_get(name: &str) -> String {
if let Ok(v) = env::var(name) { if let Ok(v) = env::var(name) {
v v
} else { } else {
panic!("{} not set", name) panic!("{name} not set")
} }
} }

View File

@ -94,8 +94,8 @@ fn interpolate_paths(paths: String) -> String {
let varname = c.as_str().replace(['$', '{', '}'], ""); let varname = c.as_str().replace(['$', '{', '}'], "");
if let Ok(replacement) = &env_var::get(&varname) { if let Ok(replacement) = &env_var::get(&varname) {
newtext = newtext newtext = newtext
.replace(&format!("${}", varname), replacement) .replace(&format!("${varname}"), replacement)
.replace(&format!("${{{}}}", varname), replacement); .replace(&format!("${{{varname}}}"), replacement);
} }
} }
} }

View File

@ -38,7 +38,7 @@ fn parse(out: Output, opts: Opts) -> Result<String> {
_ => { _ => {
let err = String::from_utf8(out.stderr) let err = String::from_utf8(out.stderr)
.unwrap_or_else(|_| "<stderr contains invalid UTF-8>".to_owned()); .unwrap_or_else(|_| "<stderr contains invalid UTF-8>".to_owned());
panic!("External command failed:\n {}", err) panic!("External command failed:\n {err}")
} }
}; };
@ -74,12 +74,12 @@ impl FinderChoice {
"--preview", "--preview",
"", "",
"--preview-window", "--preview-window",
format!("up:{}:nohidden", preview_height).as_str(), format!("up:{preview_height}:nohidden").as_str(),
"--delimiter", "--delimiter",
deser::terminal::DELIMITER.to_string().as_str(), deser::terminal::DELIMITER.to_string().as_str(),
"--ansi", "--ansi",
"--bind", "--bind",
format!("ctrl-j:down,ctrl-k:up{}", bindings).as_str(), format!("ctrl-j:down,ctrl-k:up{bindings}").as_str(),
"--exact", "--exact",
]); ]);

View File

@ -7,13 +7,13 @@ use std::process::Stdio;
fn apply_map(text: String, map_fn: Option<String>) -> Result<String> { fn apply_map(text: String, map_fn: Option<String>) -> Result<String> {
if let Some(m) = map_fn { if let Some(m) = map_fn {
let cmd = if CONFIG.shell().contains("fish") { let cmd = if CONFIG.shell().contains("fish") {
format!(r#"printf "%s" "{text}" | {m}"#, m = m, text = text) format!(r#"printf "%s" "{text}" | {m}"#)
} else { } else {
format!( format!(
r#"_navi_input() {{ r#"_navi_input() {{
cat <<'{eof}' cat <<'{EOF}'
{text} {text}
{eof} {EOF}
}} }}
_navi_map_fn() {{ _navi_map_fn() {{
@ -24,10 +24,7 @@ _navi_nonewline() {{
printf "%s" "$(cat)" printf "%s" "$(cat)"
}} }}
_navi_input | _navi_map_fn | _navi_nonewline"#, _navi_input | _navi_map_fn | _navi_nonewline"#
m = m,
text = text,
eof = EOF
) )
}; };

View File

@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
for (line_nr, line_result) in lines.enumerate() { for (line_nr, line_result) in lines.enumerate() {
let line = line_result let line = line_result
.with_context(|| format!("Failed to read line number {} in cheatsheet `{}`", line_nr, id))?; .with_context(|| format!("Failed to read line number {line_nr} in cheatsheet `{id}`"))?;
if should_break { if should_break {
break; break;