Skip to main content

gcli/
cli.rs

1// Copyright (C) Gear Technologies Inc.
2// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
3
4//! This crate provides the main CLI interface.
5
6use crate::{
7    app::{App, Opts},
8    cmd::Command,
9};
10use anyhow::Result;
11use clap::Parser;
12
13/// Interact with Gear API via node RPC.
14#[derive(Debug, Clone, Parser)]
15#[clap(author, version)]
16pub struct Cli {
17    #[command(flatten)]
18    opts: Opts,
19
20    /// Command to run.
21    #[command(subcommand)]
22    command: Command,
23}
24
25impl Cli {
26    pub async fn run(self) -> Result<()> {
27        App::new(self.opts).run(self.command).await
28    }
29
30    pub fn run_blocking(self) -> Result<()> {
31        tokio::runtime::Runtime::new()?.block_on(self.run())
32    }
33}