1use clap::ValueEnum;
2use lux_lib::package::PackageReq;
3use miette::{miette, Result};
4use std::{path::PathBuf, str::FromStr};
5
6#[derive(Debug, Clone)]
7pub enum PackageOrRockspec {
8 Package(PackageReq),
9 RockSpec(PathBuf),
10}
11
12#[derive(Debug, Clone, PartialEq, ValueEnum)]
13pub enum OutputFormat {
14 Json,
15 Text,
16}
17
18impl FromStr for PackageOrRockspec {
19 type Err = miette::Report;
20
21 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 let path = PathBuf::from(s);
23 if path.is_file() {
24 Ok(Self::RockSpec(path))
25 } else {
26 let pkg = PackageReq::from_str(s).map_err(|err| {
27 miette!(
28 help = format!("if '{s}' is a path to a file, ensure it exists"),
29 "No file '{s}' found and cannot parse package query: {err}",
30 )
31 })?;
32 Ok(Self::Package(pkg))
33 }
34 }
35}