Skip to content

Commit

Permalink
simplify Args
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Feb 1, 2025
1 parent 6b05526 commit 88dadcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0
run: sudo apt-get update && sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev libxkbcommon-x11-0
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: terp
Expand Down
46 changes: 7 additions & 39 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::app;
use bevy::prelude::*;
use clap::{Arg, Command, ValueHint};
use std::path::PathBuf;
use std::path::Path;

pub fn parse_cli() -> app::AppPlugin {
let matches = Command::new(clap::crate_name!())
Expand All @@ -28,10 +28,10 @@ pub fn parse_cli() -> app::AppPlugin {

match matches.subcommand() {
Some(("editor", editor_matches)) => {
app::AppPlugin::Editor(Args::from(editor_matches.get_one::<String>("project")))
app::AppPlugin::Editor(Args::new(editor_matches.get_one::<String>("project")))
}
Some(("player", player_matches)) => {
app::AppPlugin::Player(Args::from(player_matches.get_one::<String>("project")))
app::AppPlugin::Player(Args::new(player_matches.get_one::<String>("project")))
}
None => app::AppPlugin::Editor(Args::new(None)),
_ => unreachable!("All commands covered"),
Expand All @@ -41,53 +41,21 @@ pub fn parse_cli() -> app::AppPlugin {
#[derive(Resource, Clone, Debug)]
pub struct Args {
/// Project file
project: Option<PathBuf>,
project: Option<String>,
}

impl Args {
pub fn new(project: Option<&str>) -> Self {
pub fn new(project: Option<&String>) -> Self {
Self {
project: project.map(|p| p.into()),
}
}

pub fn project(&self) -> Option<&std::path::Path> {
pub fn project(&self) -> Option<&Path> {
if let Some(ref project) = self.project {
Some(project.as_path())
Some(Path::new(project))
} else {
None
}
}
}

impl From<&str> for Args {
fn from(value: &str) -> Self {
Self {
project: Some(value.into()),
}
}
}

impl From<&String> for Args {
fn from(value: &String) -> Self {
Self {
project: Some(value.into()),
}
}
}

impl From<Option<&str>> for Args {
fn from(value: Option<&str>) -> Self {
Self {
project: value.map(|v| v.into()),
}
}
}

impl From<Option<&String>> for Args {
fn from(value: Option<&String>) -> Self {
Self {
project: value.map(|v| v.into()),
}
}
}

0 comments on commit 88dadcf

Please sign in to comment.