Skip to content

Commit f28096e

Browse files
authored
Merge pull request #59 from SwissDataScienceCenter/rust-2024
bump rust edition to 2024
2 parents 6d9fac2 + 3e60ef6 commit f28096e

12 files changed

Lines changed: 49 additions & 54 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "rnk"
33
description = "A command line interface to the Renku platform"
44
homepage = "https://renkulab.io/"
55
version = "0.1.0-nightly"
6-
edition = "2021"
6+
edition = "2024"
77
license = "Apache-2.0"
88
repository = "https://github.com/SwissDatascienceCenter/renku-cli"
99
keywords = [ "renku", "cli" ]
@@ -34,6 +34,7 @@ url = { version = "2.5.1" }
3434
openidconnect = { version = "3.5.0", default-features = false, features = [ "reqwest" ] }
3535
directories = { version = "5.0" }
3636
comrak = { version = "0.28.0", optional = true }
37+
clap-verbosity-flag = "3.0.4"
3738

3839
[features]
3940
default = ["reqwest/default-tls"] # link against system library

rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
edition = "2021"
1+
edition = "2024"

src/cli/cmd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod version;
88
use super::sink::{Error as SinkError, Sink};
99
use crate::cli::opts::{CommonOpts, ProxySetting};
1010
use crate::data::renku_url::RenkuUrl;
11-
use crate::httpclient::{self, proxy, Client};
11+
use crate::httpclient::{self, Client, proxy};
1212
use serde::Serialize;
1313
use snafu::{ResultExt, Snafu};
1414

src/cli/cmd/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::path::{Path, PathBuf};
22

33
use super::Context;
4-
use crate::httpclient::auth::{Response, UserCode};
54
use crate::httpclient::Error as HttpError;
5+
use crate::httpclient::auth::{Response, UserCode};
66
use crate::{cli::sink::Error as SinkError, data::simple_message::SimpleMessage};
77
use clap::{Parser, ValueHint};
88

src/cli/cmd/project/clone.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ impl Input {
6767
pub async fn exec(&self, ctx: Context) -> Result<(), Error> {
6868
let opt_details = ctx
6969
.client
70-
.get_project(&self.project_ref, ctx.opts.verbose > 1)
70+
.get_project(
71+
&self.project_ref,
72+
ctx.opts.verbosity.log_level().unwrap_or(log::Level::Warn) > log::Level::Info,
73+
)
7174
.await
7275
.context(HttpClientSnafu)?;
7376
if let Some(details) = opt_details {
@@ -169,7 +172,7 @@ async fn clone_repository(
169172
.await
170173
.context(TaskJoinSnafu)?;
171174
let git_repo = repo?;
172-
if ctx.opts.verbose > 1 {
175+
if ctx.opts.verbosity.log_level().unwrap_or(log::Level::Warn) > log::Level::Info {
173176
let head = git_repo
174177
.head()
175178
.ok()

src/cli/cmd/shell_completion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{Command, Parser, ValueEnum};
2-
use clap_complete::{generate, Generator, Shell};
2+
use clap_complete::{Generator, Shell, generate};
33

44
/// Generates completions for some shells.
55
///
@@ -37,6 +37,6 @@ impl Input {
3737
}
3838
}
3939

40-
fn generate_completions<G: Generator>(gen: G, binary: &str, app: &mut Command) {
41-
generate(gen, app, binary, &mut std::io::stdout());
40+
fn generate_completions<G: Generator>(generator: G, binary: &str, app: &mut Command) {
41+
generate(generator, app, binary, &mut std::io::stdout());
4242
}

src/cli/cmd/version.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use super::Context;
2+
use crate::cli::BuildInfo;
23
use crate::cli::sink::Error as SinkError;
34
use crate::cli::sink::Sink;
4-
use crate::cli::BuildInfo;
5-
use crate::httpclient::data::VersionInfo;
65
use crate::httpclient::Error as HttpError;
6+
use crate::httpclient::data::VersionInfo;
77
use clap::Parser;
88
use serde::Serialize;
99
use snafu::{ResultExt, Snafu};
@@ -38,7 +38,9 @@ impl Input {
3838
} else {
3939
let result = ctx
4040
.client
41-
.version(ctx.opts.verbose > 1)
41+
.version(
42+
ctx.opts.verbosity.log_level().unwrap_or(log::Level::Warn) > log::Level::Info,
43+
)
4244
.await
4345
.context(HttpClientSnafu)?;
4446
let urlstr = ctx.renku_url().as_str();

src/cli/opts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::data::renku_url::RenkuUrl;
22

33
use super::cmd::*;
4-
use clap::{ArgAction, Parser, ValueEnum, ValueHint};
4+
use clap::{Parser, ValueEnum, ValueHint};
5+
use clap_verbosity_flag::{Verbosity, WarnLevel};
56
use serde::{Deserialize, Serialize};
67
use std::str::FromStr;
78

@@ -12,8 +13,8 @@ use std::str::FromStr;
1213
pub struct CommonOpts {
1314
/// Be more verbose when logging. Verbosity increases with each
1415
/// occurence of that option.
15-
#[arg(short, long, action = ArgAction::Count)]
16-
pub verbose: u8,
16+
#[command(flatten)]
17+
pub verbosity: Verbosity<WarnLevel>,
1718

1819
/// How to format the output. The default is human readable which
1920
/// may choose to not show every detail for better readability.

src/main.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use rnk::error::{Error, Result};
2-
use std::env;
32
use std::process;
43

5-
const LOG_LEVEL: &str = "RUST_LOG";
6-
74
#[tokio::main]
85
async fn main() {
96
let error_style = console::Style::new().red().bright();
@@ -16,36 +13,15 @@ async fn main() {
1613

1714
async fn execute() -> Result<()> {
1815
let opts = rnk::read_args();
19-
let remove_env = match opts.common_opts.verbose {
20-
1 => set_log_level("info"),
21-
n => {
22-
if n > 1 {
23-
set_log_level("debug")
24-
} else {
25-
false
26-
}
27-
}
28-
};
29-
env_logger::init();
16+
env_logger::Builder::new()
17+
.filter_level(opts.common_opts.verbosity.log_level_filter())
18+
.init();
3019

3120
let result = rnk::execute_cmd(opts).await;
32-
if remove_env {
33-
env::remove_var(LOG_LEVEL);
34-
}
3521
result?;
3622
Ok(())
3723
}
3824

39-
fn set_log_level(level: &str) -> bool {
40-
let current = env::var_os(LOG_LEVEL);
41-
if current.is_none() {
42-
env::set_var(LOG_LEVEL, level);
43-
true
44-
} else {
45-
false
46-
}
47-
}
48-
4925
fn exit_code(err: &Error) -> i32 {
5026
match err {
5127
Error::Cmd { source: _ } => 1,

0 commit comments

Comments
 (0)