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
use std::process::Command;
pub struct Targets(Vec<u8>);
impl Targets {
pub fn iter(&self) -> Result<TargetsIter, std::str::Utf8Error> {
std::str::from_utf8(&self.0)
.map(str::lines)
.map(TargetsIter)
}
}
pub struct TargetsIter<'a>(std::str::Lines<'a>);
impl<'a> Iterator for TargetsIter<'a> {
type Item = &'a str;
fn next(&mut self) -> Option<Self::Item> {
self.0.next()
}
}
#[doc = include_str!("../examples/targets.rs")]
pub fn from_cli() -> Result<Targets, std::io::Error> {
let output = Command::new("go")
.arg("tool")
.arg("dist")
.arg("list")
.output()?;
Ok(Targets(output.stdout))
}