Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix publish script #825

Merged
merged 5 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.68.2"
channel = "1.67.0"
components = [ "rustfmt", "clippy" ]
7 changes: 3 additions & 4 deletions src/clients/cheatsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ 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)
.collect()
}

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)
Expand Down
14 changes: 6 additions & 8 deletions src/clients/tldr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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));
}
Expand Down
10 changes: 5 additions & 5 deletions src/commands/core/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
)
Expand All @@ -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;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ pub fn act(

match CONFIG.action() {
Action::Print => {
println!("{}", interpolated_snippet);
println!("{interpolated_snippet}");
}
Action::Execute => match key {
"ctrl-y" => {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/func/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/preview/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);

Expand Down
6 changes: 3 additions & 3 deletions src/commands/preview/var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/commands/repo/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/repo/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Runnable for Input {
Shell::Elvish => include_str!("../../shell/navi.plugin.elv"),
};

println!("{}", content);
println!("{content}");

Ok(())
}
Expand Down
7 changes: 2 additions & 5 deletions src/common/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
Expand Down
2 changes: 1 addition & 1 deletion src/common/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(':', "/");
Expand Down
2 changes: 1 addition & 1 deletion src/common/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
7 changes: 2 additions & 5 deletions src/common/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/config/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/env_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/finder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
};

Expand Down Expand Up @@ -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",
]);

Expand Down
11 changes: 4 additions & 7 deletions src/finder/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {{
Expand All @@ -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"#
)
};

Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down