Skip to content

Commit

Permalink
Merge pull request #346 from tgauth/fix-table-methods-column
Browse files Browse the repository at this point in the history
use bit flags for methods in table view
SteveL-MSFT authored Mar 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents eca2155 + 7dd0275 commit e2a1b3d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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()
]);

0 comments on commit e2a1b3d

Please sign in to comment.