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

use bit flags for methods in table view #346

Merged
merged 7 commits into from
Mar 6, 2024
Merged
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
ResourceSubCommand::List { resource_name, description, tags, format } => {

let mut write_table = false;
let mut methods: Vec<String> = Vec::new();
let mut table = Table::new(&["Type", "Kind", "Version", "Methods", "Requires", "Description"]);
if format.is_none() && atty::is(Stream::Stdout) {
// write as table if format is not specified and interactive
write_table = true;
}
for resource in dsc.list_available_resources(&resource_name.clone().unwrap_or_default()) {
let mut methods = "g---".to_string();
// if description, tags, or write_table is specified, pull resource manifest if it exists
if description.is_some() || tags.is_some() || write_table {
let Some(ref resource_manifest) = resource.manifest else {
Expand Down Expand Up @@ -442,18 +442,17 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
if !found { continue; }
}

methods = vec!["get".to_string()];
if manifest.set.is_some() { methods.push("set".to_string()); }
if manifest.test.is_some() { methods.push("test".to_string()); }
if manifest.export.is_some() { methods.push("export".to_string()); }
if manifest.set.is_some() { methods.replace_range(1..2, "s"); }
if manifest.test.is_some() { methods.replace_range(2..3, "t"); }
if manifest.export.is_some() { methods.replace_range(3..4, "e"); }
}

if write_table {
table.add_row(vec![
resource.type_name,
format!("{:?}", resource.kind),
resource.version,
methods.join(", "),
methods,
resource.requires.unwrap_or_default(),
resource.description.unwrap_or_default()
]);
Expand Down
Loading