cargo_actions/
lib.rs

1mod init;
2use check::CheckArgs;
3use clap::Parser;
4use init::InitArgs;
5use login::login;
6use upload::UploadArgs;
7mod check;
8mod client;
9mod favorite;
10pub mod git;
11mod graphql;
12mod login;
13pub mod logs;
14mod mine;
15mod path_configs;
16mod token;
17mod upload;
18const CARGO_ACTIONS_URL: &str = "https://actions-workflow.shuttleapp.rs";
19const CARGO_ACTIONS_FRONT_URL: &str = "https://yexiyue.github.io/actions-workflow";
20
21pub trait Run {
22    fn run(&mut self) -> anyhow::Result<()>;
23}
24
25#[derive(Debug, Parser)]
26#[command(name = "cargo actions", bin_name = "cargo")]
27pub enum CargoAction {
28    #[command(subcommand, author, version, about, name = "actions", alias = "act")]
29    Actions(ActionsArgs),
30}
31
32/// Represents different actions that can be performed by the application.
33#[derive(Debug, Parser)]
34pub enum ActionsArgs {
35    /// Initializes a new GitHub Actions workflow in your project.
36    Init(InitArgs),
37
38    /// Authenticates the user with GitHub.
39    Login,
40
41    /// Uploads a custom template to Cargo Actions for future use.
42    Upload(UploadArgs),
43
44    /// Initializes a GitHub Actions workflow based on a template saved by the user.
45    Mine,
46
47    /// Initializes a GitHub Actions workflow using a template from the user's favorites.
48    Favorite,
49
50    /// Use local templates for initialization to check the templates
51    Check(CheckArgs),
52}
53
54impl Run for CargoAction {
55    fn run(&mut self) -> anyhow::Result<()> {
56        match self {
57            Self::Actions(action) => action.run(),
58        }
59    }
60}
61
62impl Run for ActionsArgs {
63    fn run(&mut self) -> anyhow::Result<()> {
64        match self {
65            Self::Init(init) => init.run(),
66            Self::Login => login(),
67            Self::Upload(upload) => upload.run(),
68            Self::Mine => mine::run(),
69            Self::Favorite => favorite::run(),
70            Self::Check(check) => check.run(),
71        }
72    }
73}
74
75
76pub fn cargo_run(){
77    let mut cargo_action = CargoAction::parse();
78
79    match cargo_action.run() {
80        Ok(_) => {}
81        Err(e) => {
82            error!("{e}");
83            std::process::exit(1);
84        }
85    }
86}
87
88pub fn run(){
89    let mut actions=ActionsArgs::parse();
90    match actions.run() {
91        Ok(_) => {}
92        Err(e) => {
93            error!("{e}");
94            std::process::exit(1);
95        }
96    }
97}