1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
use agent::SmAgentConfig;
use structopt::*;
mod agent;
mod error;
mod operation_logs;
mod restart_operation_handler;
mod state;
#[derive(Debug, StructOpt)]
#[structopt(
name = clap::crate_name!(),
version = clap::crate_version!(),
about = clap::crate_description!()
)]
pub struct AgentOpt {
/// Turn-on the debug log level.
///
/// If off only reports ERROR, WARN, and INFO
/// If on also reports DEBUG and TRACE
#[structopt(long)]
pub debug: bool,
/// Start the agent with clean session off, subscribe to the topics, so that no messages are lost
#[structopt(short, long)]
pub init: bool,
/// Start the agent with clean session on, drop the previous session and subscriptions
///
/// WARNING: All pending messages will be lost.
#[structopt(short, long)]
pub clear: bool,
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let agent_opt = AgentOpt::from_args();
tedge_utils::logging::initialise_tracing_subscriber(agent_opt.debug);
let tedge_config_location = tedge_config::TEdgeConfigLocation::from_default_system_location();
let mut agent = agent::SmAgent::try_new(
"tedge_agent",
SmAgentConfig::try_new(tedge_config_location)?,
)?;
if agent_opt.init {
agent.init_session().await?;
} else if agent_opt.clear {
agent.clear_session().await?;
} else {
agent.start().await?;
}
Ok(())
}
|