Skip to content

Commit c8815cb

Browse files
author
Brendan Molloy
committedFeb 5, 2019
Add support for channels more broadly
1 parent f1602b4 commit c8815cb

File tree

5 files changed

+256
-193
lines changed

5 files changed

+256
-193
lines changed
 

‎Cargo.toml

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22
name = "pahkat"
33
version = "0.6.0"
44
authors = ["Brendan Molloy <brendan@bbqsrc.net>"]
5+
edition = "2018"
56

67
[[bin]]
78
name = "pahkat"
89
path = "src/main.rs"
910
required-features = ["binaries"]
1011

1112
[dependencies]
12-
clap = { version = "*", optional = true }
13-
termcolor = { version = "0.3", optional = true }
13+
clap = { version = "2.32.0", optional = true }
14+
dialoguer = { version = "0.3.0", optional = true }
15+
termcolor = { version = "1.0.4", optional = true }
1416
pathdiff = { version = "0.1", optional = true }
15-
serde = "*"
16-
serde_derive = "*"
17-
serde_json = "*"
17+
url = { version = "1.7.2", optional = true}
18+
serde = "1.0.87"
19+
serde_derive = "1.0.87"
20+
serde_json = "1.0.38"
1821

1922
[features]
20-
binaries = ["clap", "termcolor", "pathdiff"]
23+
binaries = ["clap", "termcolor", "pathdiff", "dialoguer", "url"]

‎src/cli.rs

+38-62
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,55 @@ use std::io;
22
use std::io::Write;
33
use std::collections::BTreeMap;
44
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
5-
6-
#[cfg(target_os = "windows")]
7-
pub const INPUT_DEFAULT_LEN: usize = 2;
8-
#[cfg(not(target_os = "windows"))]
9-
pub const INPUT_DEFAULT_LEN: usize = 1;
5+
use dialoguer::{Confirmation, Input, Checkboxes, Select, theme::ColorfulTheme};
106

117
pub fn progress(color: Color, first: &str, rest: &str) -> Result<(), io::Error> {
12-
let mut stdout = StandardStream::stdout(ColorChoice::Always);
13-
try!(stdout.set_color(ColorSpec::new().set_fg(Some(color))
8+
let mut stderr = StandardStream::stderr(ColorChoice::Always);
9+
stderr.set_color(ColorSpec::new().set_fg(Some(color))
1410
.set_intense(true)
15-
.set_bold(true)));
16-
try!(write!(&mut stdout, "{:>12}", first));
17-
stdout.reset()?;
18-
writeln!(&mut stdout, " {}", rest)?;
11+
.set_bold(true))?;
12+
write!(&mut stderr, "{:>12}", first)?;
13+
stderr.reset()?;
14+
writeln!(&mut stderr, " {}", rest)?;
1915
Ok(())
2016
}
2117

2218
pub fn prompt_question(prompt: &str, default: bool) -> bool {
23-
let mut stdout = StandardStream::stdout(ColorChoice::Always);
24-
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Cyan))).unwrap();
25-
write!(&mut stdout, "{}? ", prompt).unwrap();
26-
stdout.reset().unwrap();
27-
28-
print!("({}) ", if default { "yes" } else { "no" });
29-
30-
let _ = io::stdout().flush();
31-
let mut input = String::new();
32-
33-
fn parse(it: &str) -> bool {
34-
let lower = it.to_lowercase();
35-
36-
if lower == "y" || lower == "yes" {
37-
return true;
38-
}
39-
40-
false
41-
}
42-
43-
match io::stdin().read_line(&mut input) {
44-
Ok(n) => {
45-
match n {
46-
0 => false,
47-
INPUT_DEFAULT_LEN => default,
48-
_ => parse(input.trim())
49-
}
50-
}
51-
Err(error) => panic!(error)
52-
}
19+
Confirmation::with_theme(&ColorfulTheme::default())
20+
.with_text(prompt)
21+
.default(default)
22+
.interact()
23+
.unwrap_or(default)
5324
}
5425

5526
pub fn prompt_line(prompt: &str, default: &str) -> Option<String> {
56-
let mut stdout = StandardStream::stdout(ColorChoice::Always);
57-
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Cyan))).unwrap();
58-
write!(&mut stdout, "{}: ", prompt).unwrap();
59-
stdout.reset().unwrap();
60-
61-
if default != "" {
62-
print!("({}) ", default);
63-
}
64-
65-
let _ = io::stdout().flush();
66-
let mut input = String::new();
27+
Some(Input::with_theme(&ColorfulTheme::default())
28+
.with_prompt(prompt)
29+
.default(default.to_string())
30+
.interact()
31+
.unwrap_or(default.to_string())
32+
.to_string())
33+
}
6734

68-
match io::stdin().read_line(&mut input) {
69-
Ok(n) => {
70-
match n {
71-
0 => None,
72-
INPUT_DEFAULT_LEN => Some(default.to_owned()),
73-
_ => Some(input.trim().to_owned())
74-
}
75-
}
76-
Err(error) => panic!(error)
77-
}
35+
pub fn prompt_multi_select(prompt: &str, options: &[&str]) -> Vec<String> {
36+
Checkboxes::with_theme(&ColorfulTheme::default())
37+
.with_prompt(prompt)
38+
.items(options)
39+
.interact()
40+
.unwrap_or(vec![])
41+
.into_iter()
42+
.map(|i| options[i].to_string())
43+
.collect()
44+
}
45+
46+
pub fn prompt_select(prompt: &str, options: &[String], default: usize) -> String {
47+
Select::with_theme(&ColorfulTheme::default())
48+
.with_prompt(prompt)
49+
.items(options)
50+
.default(default)
51+
.interact()
52+
.map(|i| options[i].to_string())
53+
.unwrap_or_else(|_| options[default].to_string())
7854
}
7955

8056
pub fn parse_platform_list(vec: &[String]) -> BTreeMap<String, String> {

‎src/main.rs

+205-97
Large diffs are not rendered by default.

‎src/types/mod.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct Packages {
6363
#[serde(rename = "@id")]
6464
pub _id: Option<String>,
6565
pub base: String,
66+
pub channel: String,
6667
#[serde(default = "BTreeMap::new")]
6768
pub packages: PackageMap
6869
}
@@ -95,6 +96,7 @@ pub struct Virtuals {
9596
#[serde(rename = "@id")]
9697
pub _id: Option<String>,
9798
pub base: String,
99+
pub channel: String,
98100
#[serde(default = "BTreeMap::new")]
99101
pub virtuals: VirtualRefMap
100102
}
@@ -118,7 +120,6 @@ pub enum Installer {
118120
Windows(WindowsInstaller),
119121
MacOS(MacOSInstaller),
120122
Tarball(TarballInstaller),
121-
// MacOSBundle(MacOSBundleInstaller)
122123
}
123124

124125
impl Downloadable for Installer {
@@ -127,36 +128,10 @@ impl Downloadable for Installer {
127128
Installer::Windows(ref v) => v.url.to_owned(),
128129
Installer::MacOS(ref v) => v.url.to_owned(),
129130
Installer::Tarball(ref v) => v.url.to_owned(),
130-
// Installer::MacOSBundle(ref v) => v.url.to_owned()
131131
}
132132
}
133133
}
134134

135-
// #[derive(Default, Debug, Serialize, Deserialize)]
136-
// #[serde(rename_all = "camelCase")]
137-
// pub struct MacOSBundleInstallPath {
138-
// pub user: Option<String>,
139-
// pub system: Option<String>
140-
// }
141-
142-
/// This type is for .bundle files which include an Info.plist for versioning purposes
143-
// #[derive(Debug, Serialize, Deserialize)]
144-
// #[serde(rename_all = "camelCase")]
145-
// pub struct MacOSBundleInstaller {
146-
// #[serde(rename = "@type")]
147-
// pub _type: Option<String>,
148-
// pub url: String,
149-
// #[serde(default)]
150-
// pub install_path: MacOSBundleInstallPath,
151-
// #[serde(default)]
152-
// pub requires_reboot: bool,
153-
// #[serde(default)]
154-
// pub requires_uninstall_reboot: bool,
155-
// pub size: usize,
156-
// pub installed_size: usize,
157-
// pub signature: Option<InstallerSignature>
158-
// }
159-
160135
#[derive(Debug, Clone, Copy, Eq, Serialize, Deserialize)]
161136
#[serde(rename_all = "camelCase")]
162137
pub enum InstallTarget {

‎src/types/repo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ pub struct Repository {
77
pub _context: Option<String>,
88
#[serde(rename = "@type")]
99
pub _type: Option<String>,
10-
pub agent: Option<RepositoryAgent>,
10+
pub agent: RepositoryAgent,
1111
pub base: String,
1212
pub name: BTreeMap<String, String>,
1313
#[serde(default = "BTreeMap::new")]
1414
pub description: BTreeMap<String, String>,
1515
pub primary_filter: String,
16+
pub default_channel: String,
1617
pub channels: Vec<String>,
1718
#[serde(default = "BTreeMap::new")]
1819
pub categories: BTreeMap<String, BTreeMap<String, String>>

0 commit comments

Comments
 (0)
Please sign in to comment.