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
id: get_version
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
uses: svenstaro/upload-release-action@v1-release
with:

View File

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

View File

@ -7,9 +7,8 @@ fn map_line(line: &str) -> String {
fn as_lines(query: &str, markdown: &str) -> Vec<String> {
format!(
"% {}, cheat.sh
{}",
query, markdown
"% {query}, cheat.sh
{markdown}"
)
.lines()
.map(map_line)
@ -17,7 +16,7 @@ fn as_lines(query: &str, markdown: &str) -> 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")
.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();
if let Some(c) = new_var.chars().next() {
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
@ -42,9 +42,8 @@ fn convert_tldr(line: &str) -> String {
fn markdown_lines(query: &str, markdown: &str) -> Vec<String> {
format!(
"% {}, tldr
{}",
query, markdown
"% {query}, tldr
{markdown}"
)
.lines()
.map(convert_tldr)
@ -70,9 +69,8 @@ Make sure tldr is correctly installed.
Refer to https://github.com/tldr-pages/tldr for more info.
Note:
{}
",
VERSION_DISCLAIMER
{VERSION_DISCLAIMER}
"
);
return Err(anyhow!(msg));
}

View File

@ -77,7 +77,7 @@ fn prompt_finder(
name = variable_name,
extra = extra_preview
.clone()
.map(|e| format!(" echo; {}", e))
.map(|e| format!(" echo; {e}"))
.unwrap_or_default(),
)
} else {
@ -93,7 +93,7 @@ fn prompt_finder(
name = variable_name,
extra = extra_preview
.clone()
.map(|e| format!(" echo; {}", e))
.map(|e| format!(" echo; {e}"))
.unwrap_or_default(),
eof = EOF,
)
@ -105,9 +105,9 @@ fn prompt_finder(
..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.suggestion_type = SuggestionType::SingleSelection;
}
@ -229,7 +229,7 @@ pub fn act(
match CONFIG.action() {
Action::Print => {
println!("{}", interpolated_snippet);
println!("{interpolated_snippet}");
}
Action::Execute => match key {
"ctrl-y" => {

View File

@ -11,7 +11,7 @@ pub fn last_command() -> Result<()> {
for p in parts {
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);
text = text.replace(&p, &replacement);
}

View File

@ -30,7 +30,7 @@ impl Runnable for Input {
println!(
"{comment} {tags} \n{snippet}",
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()),
);

View File

@ -42,10 +42,10 @@ impl Runnable for Input {
println!(
"{comment} {tags}",
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> = {
if snippet.contains(&bracketed_current_variable) {
@ -102,7 +102,7 @@ impl Runnable for Input {
}
println!("{snippet}", snippet = deser::fix_newlines(&colored_snippet));
println!("{variables}", variables = variables);
println!("{variables}");
process::exit(0)
}

View File

@ -41,13 +41,13 @@ pub fn main(uri: String) -> Result<()> {
eprintln!("Cloning {} into {}...\n", &actual_uri, &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 opts = FinderOpts {
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()),
preview_window: Some("right:30%".to_string()),
..Default::default()
@ -69,7 +69,7 @@ pub fn main(uri: String) -> Result<()> {
let to_folder = {
let mut p = cheat_pathbuf;
p.push(format!("{}__{}", user, repo));
p.push(format!("{user}__{repo}"));
p
};

View File

@ -21,7 +21,7 @@ pub fn main() -> Result<String> {
let (repo_url, _, _) = git::meta("denisidoro/cheats");
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 mut p = repo_pathbuf.clone();

View File

@ -27,13 +27,13 @@ impl Runnable for Input {
match &self.cmd {
RepoCommand::Add { uri } => {
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()
}
RepoCommand::Browse => {
let repo = browse::main().context("Failed to browse featured cheatsheets")?;
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()
}
}

View File

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

View File

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

View File

@ -16,7 +16,7 @@ pub fn meta(uri: &str) -> (String, String, String) {
let actual_uri = if uri.contains("://") || uri.contains('@') {
uri.to_string()
} else {
format!("https://github.com/{}", uri)
format!("https://github.com/{uri}")
};
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> {
style::Color::parse_ansi(&format!("5;{}", ansi))
style::Color::parse_ansi(&format!("5;{ansi}"))
}
#[derive(Debug, Clone)]

View File

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

View File

@ -22,7 +22,7 @@ impl Config {
pub fn new() -> Self {
let env = EnvConfig::new();
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!();
YamlConfig::default()

View File

@ -21,7 +21,7 @@ where
{
let s: String = Deserialize::deserialize(deserializer)?;
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)]
@ -55,7 +55,7 @@ where
{
let s: String = Deserialize::deserialize(deserializer)?;
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)]

View File

@ -31,7 +31,7 @@ pub fn must_get(name: &str) -> String {
if let Ok(v) = env::var(name) {
v
} 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(['$', '{', '}'], "");
if let Ok(replacement) = &env_var::get(&varname) {
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)
.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-window",
format!("up:{}:nohidden", preview_height).as_str(),
format!("up:{preview_height}:nohidden").as_str(),
"--delimiter",
deser::terminal::DELIMITER.to_string().as_str(),
"--ansi",
"--bind",
format!("ctrl-j:down,ctrl-k:up{}", bindings).as_str(),
format!("ctrl-j:down,ctrl-k:up{bindings}").as_str(),
"--exact",
]);

View File

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

View File

@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
for (line_nr, line_result) in lines.enumerate() {
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 {
break;