forked from HewlettPackard/dockerfile-parser-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstages.rs
41 lines (32 loc) · 935 Bytes
/
stages.rs
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
// (C) Copyright 2019 Hewlett Packard Enterprise Development LP
use std::fs::File;
use snafu::ErrorCompat;
use dockerfile_parser::{Result, Dockerfile};
fn wrap() -> Result<()> {
let args: Vec<String> = std::env::args().collect();
let path = args.get(1).expect("a path to a Dockerfile is required");
let f = File::open(path).expect("file must be readable");
let dockerfile = Dockerfile::from_reader(f)?;
for stage in dockerfile.iter_stages() {
println!(
"stage #{} (parent: {:?}, root: {:?})",
stage.index, stage.parent, stage.root
);
for ins in stage.instructions {
println!(" {:?}", ins);
}
}
Ok(())
}
fn main() {
match wrap() {
Ok(()) => std::process::exit(0),
Err(e) => {
eprintln!("An error occurred: {}", e);
if let Some(backtrace) = ErrorCompat::backtrace(&e) {
eprintln!("{}", backtrace);
}
std::process::exit(1);
}
}
}