-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start work on rewriting add subcommand
- Loading branch information
1 parent
f4f7196
commit 6af0c2e
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
use aftman::{storage::Home, tool::ToolAlias}; | ||
|
||
use crate::util::ToolIdOrSpec; | ||
|
||
/// Adds a new tool to Aftman and installs it. | ||
#[derive(Debug, Parser)] | ||
pub struct AddSubcommand { | ||
/// A tool identifier or specification describing where | ||
/// to get the tool and what version to install. | ||
pub tool_spec: ToolIdOrSpec, | ||
|
||
/// The name that will be used to run the tool. | ||
pub tool_alias: Option<ToolAlias>, | ||
|
||
/// Install this tool globally by adding it to ~/.aftman/aftman.toml | ||
/// instead of installing it to the nearest aftman.toml file. | ||
#[clap(long)] | ||
pub global: bool, | ||
} | ||
|
||
impl AddSubcommand { | ||
pub async fn run(&self, home: &Home) -> Result<()> { | ||
// TODO: Implement the add subcommand | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::str::FromStr; | ||
|
||
use serde_with::DeserializeFromStr; | ||
|
||
use aftman::tool::{ToolId, ToolSpec, ToolSpecParseError}; | ||
|
||
/** | ||
A tool identifier *or* specification, which includes | ||
the author, name, and *maybe* a version of a tool. | ||
See [`ToolId`] and [`ToolSpec`] for more information. | ||
*/ | ||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, DeserializeFromStr)] | ||
pub enum ToolIdOrSpec { | ||
Id(ToolId), | ||
Spec(ToolSpec), | ||
} | ||
|
||
impl FromStr for ToolIdOrSpec { | ||
type Err = ToolSpecParseError; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.contains('@') { | ||
Ok(Self::Spec(s.parse()?)) | ||
} else { | ||
Ok(Self::Id(s.parse()?)) | ||
} | ||
} | ||
} | ||
|
||
impl From<ToolId> for ToolIdOrSpec { | ||
fn from(id: ToolId) -> Self { | ||
Self::Id(id) | ||
} | ||
} | ||
|
||
impl From<ToolSpec> for ToolIdOrSpec { | ||
fn from(spec: ToolSpec) -> Self { | ||
Self::Spec(spec) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod id_or_spec; | ||
|
||
pub use self::id_or_spec::ToolIdOrSpec; |