Skip to content

Commit

Permalink
Add lib version to version info
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex authored and fabricereix committed Oct 24, 2021
1 parent 49f7a32 commit 1cb6530
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/hurl/src/cli/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::cli::CliError;
use crate::http::ClientOptions;
use crate::runner::Value;
use atty::Stream;
use clap::{AppSettings, ArgMatches};
use clap::{App, AppSettings, ArgMatches};
use std::collections::HashMap;
use std::fs::File;
use std::io::{BufRead, BufReader};
Expand Down Expand Up @@ -68,9 +68,8 @@ pub struct CliOptions {
pub verbose: bool,
}

pub fn app() -> clap::App<'static, 'static> {
clap::App::new("hurl")
.version(clap::crate_version!())
pub fn app() -> App<'static, 'static> {
App::new("hurl")
.about("Run hurl FILE(s) or standard input")
.setting(AppSettings::DeriveDisplayOrder)
.setting(AppSettings::UnifiedHelpMessage)
Expand Down
40 changes: 39 additions & 1 deletion packages/hurl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
*/

use std::fmt::Write as FmtWrite;
use std::io::prelude::*;
use std::io::{self};
use std::path::{Path, PathBuf};
Expand All @@ -24,6 +25,7 @@ use std::time::Instant;
use atty::Stream;
use colored::*;

use curl::Version;
use hurl::cli;
use hurl::cli::{CliError, CliOptions};
use hurl::http;
Expand Down Expand Up @@ -247,9 +249,11 @@ pub fn unwrap_or_exit<T>(
}

fn main() {
let app = cli::app();
let version_info = get_version_info();
let app = cli::app().version(version_info.as_str());
let matches = app.clone().get_matches();
init_colored();

let mut filenames = match matches.values_of("INPUT") {
None => vec![],
Some(v) => v.collect(),
Expand Down Expand Up @@ -564,3 +568,37 @@ fn print_summary(duration: u128, hurl_results: Vec<HurlResult>) {
);
eprintln!("Duration: {}ms", duration);
}

fn get_version_info() -> String {
let mut ver_string = String::new();
let curl_v = Version::get();
writeln!(ver_string, clap::crate_version!()).expect("Failed to write hurl version string");
for (lib, ver) in [
("libcurl", Some(curl_v.version())),
("", curl_v.ssl_version()),
("zlib", curl_v.libz_version()),
("", curl_v.nghttp2_version()),
("ares", curl_v.ares_version()),
("brotli", curl_v.brotli_version()),
("gsasl", curl_v.gsasl_version()),
("hyper", curl_v.hyper_version()),
(
"iconv",
curl_v.iconv_version_num().map(|v| v.to_string()).as_deref(),
),
("libidn", curl_v.libidn_version()),
("libssh", curl_v.libssh_version()),
("quic", curl_v.quic_version()),
] {
if let Some(version) = ver {
if !lib.is_empty() {
write!(ver_string, "{}/{} ", lib, version)
.expect("Failed to write custom lib version");
} else {
write!(ver_string, "{} ", version).expect("Failed to write lib version string");
}
}
}
writeln!(ver_string).expect("Failed to write version string");
ver_string
}

0 comments on commit 1cb6530

Please sign in to comment.