Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/agama-cli/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use url::Url;

use crate::auth_tokens_file::AuthTokensFile;
use crate::error::CliError;
use agama_lib::base_http_client::BaseHTTPClient;
use agama_lib::http::BaseHTTPClient;
use inquire::Password;
use std::collections::HashMap;
use std::io::{self, IsTerminal};
Expand Down
10 changes: 10 additions & 0 deletions rust/agama-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ pub enum Commands {
#[clap(default_value = "reboot")]
method: Option<FinishMethod>,
},

/// Monitors the Agama service.
Monitor,

/// Display Agama events.
Events {
/// Display the events in a more human-readable way.
#[arg(short, long)]
pretty: bool,
},
}
17 changes: 11 additions & 6 deletions rust/agama-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ use std::{
process::Command,
};

use crate::show_progress;
use agama_lib::{
base_http_client::BaseHTTPClient, context::InstallationContext,
install_settings::InstallSettings, Store as SettingsStore,
context::InstallationContext, http::BaseHTTPClient, install_settings::InstallSettings,
monitor::MonitorClient, Store as SettingsStore,
};
use anyhow::anyhow;
use clap::Subcommand;
use std::io::Write;
use tempfile::Builder;

use crate::show_progress;

const DEFAULT_EDITOR: &str = "/usr/bin/vi";

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -62,7 +63,11 @@ pub enum ConfigCommands {
},
}

pub async fn run(http_client: BaseHTTPClient, subcommand: ConfigCommands) -> anyhow::Result<()> {
pub async fn run(
http_client: BaseHTTPClient,
monitor: MonitorClient,
subcommand: ConfigCommands,
) -> anyhow::Result<()> {
let store = SettingsStore::new(http_client).await?;

match subcommand {
Expand All @@ -78,7 +83,7 @@ pub async fn run(http_client: BaseHTTPClient, subcommand: ConfigCommands) -> any
stdin.read_to_string(&mut contents)?;
let result = InstallSettings::from_json(&contents, &InstallationContext::from_env()?)?;
tokio::spawn(async move {
show_progress().await.unwrap();
show_progress(monitor, true).await;
});
store.store(&result).await?;
Ok(())
Expand All @@ -90,7 +95,7 @@ pub async fn run(http_client: BaseHTTPClient, subcommand: ConfigCommands) -> any
.unwrap_or(DEFAULT_EDITOR.to_string());
let result = edit(&model, &editor)?;
tokio::spawn(async move {
show_progress().await.unwrap();
show_progress(monitor, true).await;
});
store.store(&result).await?;
Ok(())
Expand Down
38 changes: 38 additions & 0 deletions rust/agama-cli/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) [2024] SUSE LLC
//
// All Rights Reserved.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, contact SUSE LLC.
//
// To contact SUSE LLC about this file by physical or electronic mail, you may
// find current contact information at www.suse.com.

use agama_lib::http::WebSocketClient;

/// Main entry point called from Agama CLI main loop
pub async fn run(mut ws_client: WebSocketClient, pretty: bool) -> anyhow::Result<()> {
loop {
let event = ws_client.receive().await?;
let conversion = if pretty {
serde_json::to_string_pretty(&event)
} else {
serde_json::to_string(&event)
};

match conversion {
Ok(event_json) => println!("{}", event_json),
Err(_) => eprintln!("Could not serialize {:?}", &event),
}
}
}
Loading