-
-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathlist.rs
More file actions
109 lines (103 loc) · 3.26 KB
/
Copy pathlist.rs
File metadata and controls
109 lines (103 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use anyhow::Result;
use chrono::Utc;
use clap::{Arg, ArgAction, ArgMatches, Command};
use crate::api::Api;
use crate::config::Config;
use crate::utils::formatting::{HumanDuration, Table};
pub fn make_command(command: Command) -> Command {
command
.about("List the most recent releases.")
.arg(
Arg::new("show_projects")
.short('P')
.long("show-projects")
.action(ArgAction::SetTrue)
.help("Display the Projects column"),
)
.arg(
Arg::new("raw")
.short('R')
.long("raw")
.action(ArgAction::SetTrue)
.help("Print raw, delimiter separated list of releases. [defaults to new line]"),
)
.arg(
Arg::new("delimiter")
.short('D')
.long("delimiter")
.num_args(1)
.requires("raw")
.help("Delimiter for the --raw flag"),
)
// Legacy flag that has no effect, left hidden for backward compatibility
.arg(
Arg::new("no_abbrev")
.long("no-abbrev")
.action(ArgAction::SetTrue)
.hide(true),
)
}
pub fn execute(matches: &ArgMatches) -> Result<()> {
let config = Config::current();
let api = Api::current();
let project = config.get_project(matches).ok();
let releases = api
.authenticated()?
.list_releases(&config.get_org(matches)?, project.as_deref())?;
if matches.get_flag("raw") {
let versions = releases
.iter()
.map(|release_info| release_info.version.clone())
.collect::<Vec<_>>()
.join(
matches
.get_one::<String>("delimiter")
.map(String::as_str)
.unwrap_or("\n"),
);
println!("{versions}");
return Ok(());
}
let mut table = Table::new();
let title_row = table.title_row();
title_row.add("Released").add("Version");
if matches.get_flag("show_projects") {
title_row.add("Projects");
}
title_row.add("New Events").add("Last Event");
for release_info in releases {
let row = table.add_row();
if let Some(date) = release_info.date_released {
row.add(format!(
"{} ago",
HumanDuration(Utc::now().signed_duration_since(date))
));
} else {
row.add("(unreleased)");
}
row.add(&release_info.version);
if matches.get_flag("show_projects") {
let project_slugs = release_info
.projects
.into_iter()
.map(|p| p.slug)
.collect::<Vec<_>>();
if !project_slugs.is_empty() {
row.add(project_slugs.join("\n"));
} else {
row.add("-");
}
}
row.add(release_info.new_groups);
if let Some(date) = release_info.last_event {
row.add(format!(
"{} ago",
HumanDuration(Utc::now().signed_duration_since(date))
));
} else {
row.add("-");
}
}
table.print();
Ok(())
}