Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI changes [CPP-585] #378

Merged
merged 6 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion console_backend/src/bin/headless-console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Usage:
let (_server_send, server_recv) = channel::unbounded::<Vec<u8>>();
let client_send = ChannelSender::boxed(client_send_);
let shared_state = SharedState::new();
setup_logging(client_send.clone(), shared_state.clone());
let conn_manager = ConnectionManager::new(client_send.clone(), shared_state.clone());
handle_cli(opt, &conn_manager, shared_state.clone(), &client_send);
setup_logging(client_send.clone(), shared_state.clone());
refresh_connection_frontend(&client_send, &shared_state);
refresh_loggingbar(&client_send, &shared_state);
server_recv_thread(conn_manager, client_send, server_recv, shared_state);
Expand Down
124 changes: 63 additions & 61 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::{
str::FromStr,
};

use clap::Parser;
use clap::{AppSettings::DeriveDisplayOrder, Parser};
use log::{debug, error};
use strum::VariantNames;

use crate::errors::CONVERT_TO_STR_FAILURE;
use crate::log_panel::LogLevel;
use crate::output::CsvLogging;
use crate::shared_state::SharedState;
Expand All @@ -21,6 +20,7 @@ use crate::{
common_constants::{SbpLogging, Tabs},
connection::{Connection, ConnectionManager},
};
use crate::{constants::LOG_FILENAME, errors::CONVERT_TO_STR_FAILURE};

#[derive(Debug)]
pub struct CliLogLevel(LogLevel);
Expand Down Expand Up @@ -85,73 +85,76 @@ impl FromStr for CliSbpLogging {
}
}

#[cfg(windows)]
const BIN_NAME: &str = "Swift-Navigation-Console";
#[cfg(not(windows))]
const BIN_NAME: &str = "swift-navigation-console";

#[derive(Parser)]
#[clap(
name = "swift_navigation_console",
about = "Swift Navigation Console.",
version = include_str!("version.txt")
bin_name = BIN_NAME,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the name locally, not sure if that was still and issue with dists?

version = include_str!("version.txt"),
setting = DeriveDisplayOrder,
)]
pub struct CliOptions {
#[clap(subcommand)]
pub input: Option<Input>,

/// Log messages to terminal.
#[clap(long = "log-stderr")]
pub log_stderr: bool,

/// Exit when connection closes.
#[clap(long = "exit-after")]
pub exit_after: bool,

/// Enable CSV logging.
#[clap(long = "csv-log")]
pub csv_log: bool,

/// Enable SBP-JSON or SBP logging.
#[clap(long = "sbp-log")]
/// Log SBP-JSON or SBP data to default / specified log file.
#[clap(long)]
pub sbp_log: Option<CliSbpLogging>,

/// Set SBP log filename.
#[clap(long = "sbp-log-filename")]
#[clap(long)]
pub sbp_log_filename: Option<PathBuf>,

/// Set Console Log Level Filter. Default: WARNING.
#[clap(long = "log-level")]
pub log_level: Option<CliLogLevel>,

/// Set log directory.
#[clap(long = "log-dirname")]
pub dirname: Option<String>,
#[clap(long)]
pub log_dirname: Option<String>,

/// Create a log file containing console debug information.
#[clap(long)]
pub log_console: bool,

/// Log CSV data to default / specified log file.
#[clap(long)]
pub csv_log: bool,

/// Show CSV logging button.
#[clap(long)]
pub show_csv_log: bool,

// Frontend Options
/// Show Filio pane in Update tab.
#[clap(long = "show-fileio")]
#[clap(long)]
pub show_fileio: bool,

/// Allow File Connections.
#[clap(long = "show-file-connection")]
#[clap(long)]
pub show_file_connection: bool,

/// Path to a yaml file containing known piski settings.
#[clap(long)]
pub settings_yaml: Option<PathBuf>,

/// Use OpenGL, plots will become optimized for efficiency not aesthetics and require less system resources.
#[clap(long = "use-opengl", parse(from_flag = Not::not))]
#[clap(long, parse(from_flag = Not::not))]
pub use_opengl: bool,

/// Change the refresh rate of the plots.
#[clap(long = "refresh-rate", validator(is_refresh_rate))]
#[clap(long, validator(is_refresh_rate))]
pub refresh_rate: Option<u8>,

/// Start console from specific tab.
#[clap(long = "tab")]
pub tab: Option<CliTabs>,

/// Show CSV logging button.
#[clap(long = "show-csv-log")]
pub show_csv_log: bool,

/// Don't show prompts about firmware/console updates.
#[clap(long = "no-prompts")]
#[clap(long)]
pub no_prompts: bool,

/// Exit when connection closes.
#[clap(long)]
pub exit_after: bool,

/// Start console from specific tab.
#[clap(long)]
pub tab: Option<CliTabs>,

/// Set the height of the main window.
#[clap(long)]
pub height: Option<u32>,
Expand All @@ -160,9 +163,8 @@ pub struct CliOptions {
#[clap(long)]
pub width: Option<u32>,

/// Path to a yaml file containing known piski settings.
#[clap(long)]
pub settings_yaml: Option<PathBuf>,
#[clap(subcommand)]
pub input: Option<Input>,
}

impl CliOptions {
Expand Down Expand Up @@ -197,16 +199,8 @@ impl CliOptions {
}

#[derive(Parser, Debug)]
#[clap(about = "Input type and corresponding options.")]
#[clap(about = "Input type and corresponding options.", setting = DeriveDisplayOrder)]
pub enum Input {
Tcp {
/// The TCP host to connect to.
host: String,

/// The port to use when connecting via TCP.
#[clap(long, default_value = "55555")]
port: u16,
},
Serial {
/// The serialport to connect to.
#[clap(parse(from_os_str))]
Expand All @@ -220,6 +214,14 @@ pub enum Input {
#[clap(long = "flow-control", default_value = "None")]
flow_control: FlowControl,
},
Tcp {
/// The TCP host to connect to.
host: String,

/// The port to use when connecting via TCP.
#[clap(long, default_value = "55555")]
port: u16,
},
File {
/// Open and run an SBP file.
#[clap(parse(from_os_str))]
Expand Down Expand Up @@ -323,17 +325,17 @@ pub fn handle_cli(
}
}
}
if let Some(folder) = opt.dirname {
if let Some(ref path) = opt.settings_yaml {
sbp_settings::setting::load_from_path(path).expect("failed to load settings");
}
if let Some(folder) = opt.log_dirname {
shared_state.set_logging_directory(PathBuf::from(folder));
}
let log_level = if let Some(log_level_) = opt.log_level {
(*log_level_).clone()
} else {
LogLevel::WARNING
};
shared_state.set_log_level(log_level);
shared_state.lock().logging_bar.csv_logging = CsvLogging::from(opt.csv_log);
shared_state.lock().log_to_std.set(opt.log_stderr);
if opt.log_console {
let filename = chrono::Local::now().format(LOG_FILENAME).to_string().into();
shared_state.set_log_filename(Some(filename));
}
if let Some(path) = opt.sbp_log_filename {
shared_state.set_sbp_logging_filename(Some(path));
}
Expand Down
1 change: 1 addition & 0 deletions console_backend/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub(crate) const APPLICATION_NAME: &str = "swift_navigation_console";
// Logging constants
#[allow(dead_code)]
pub(crate) const LOG_WRITER_BUFFER_MESSAGE_COUNT: usize = 50;
pub(crate) const LOG_FILENAME: &str = "swift-console-%Y%m%d-%H%M%S.log";

// Main Tab constants.
pub(crate) const WRITE_TO_DEVICE_SENDER_ID: u16 = 1337;
Expand Down