type/
type.rs

1use std::env;
2use std::process;
3
4/// Parse a spot provided as a commandline argument.
5/// Output the type of spot together with the callsign of the spotter.
6/// See also `basic_run.sh` for exemplary use.
7fn main() {
8    let args: Vec<String> = env::args().collect();
9    let retval;
10
11    if args.len() != 2 {
12        eprintln!("Invalid number of arguments.");
13        eprintln!("Usage: {} <spot>", args[0]);
14        retval = 1;
15    } else {
16        match dxclparser::parse(args[1].trim().trim_end_matches('\u{0007}')) {
17            Ok(spot) => {
18                match spot {
19                    dxclparser::Spot::DX(dx) => println!("Found a DX spot from {}", dx.call_de),
20                    dxclparser::Spot::WWV(wwv) => println!("Found a WWV spot from {}", wwv.call_de),
21                    dxclparser::Spot::WCY(wcy) => println!("Found a WCY spot from {}", wcy.call_de),
22                    dxclparser::Spot::WX(wx) => println!("Found a WX spot from {}", wx.call_de),
23                    dxclparser::Spot::ToAll(toall) => {
24                        println!("Found a ToAll spot from {}", toall.call_de)
25                    }
26                    dxclparser::Spot::ToLocal(tolocal) => {
27                        println!("Found a ToLocal spot from {}", tolocal.call_de)
28                    }
29                }
30                retval = 0;
31            }
32            Err(e) => {
33                eprintln!("Failed to parse spot ({})", e);
34                retval = 1;
35            }
36        }
37    }
38
39    process::exit(retval);
40}