From c7ce071026918f761e2661ce7abf958371d14570 Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Tue, 5 Mar 2024 11:50:03 -0500 Subject: [PATCH 1/3] use bit flags for methods in table view --- dsc/src/subcommand.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index f9a03719..08586d0b 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -436,10 +436,10 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { 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()); } + methods = vec!["g".to_string()]; + if manifest.set.is_some() { methods.push("s".to_string()); } else { methods.push("-".to_string()) }; + if manifest.test.is_some() { methods.push("t".to_string()); } else { methods.push("-".to_string()) }; + if manifest.export.is_some() { methods.push("e".to_string()); } else { methods.push("-".to_string()) }; } if write_table { @@ -447,7 +447,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { resource.type_name, format!("{:?}", resource.kind), resource.version, - methods.join(", "), + methods.join(""), resource.requires.unwrap_or_default(), resource.description.unwrap_or_default() ]); From 2b15b7756eb359c2302e44f39c453670610b7bfe Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Wed, 6 Mar 2024 10:19:10 -0500 Subject: [PATCH 2/3] use replace_range for string instead of reallocating --- dsc/src/subcommand.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index 08586d0b..458c98a2 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -394,7 +394,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { ResourceSubCommand::List { resource_name, description, tags, format } => { let mut write_table = false; - let mut methods: Vec = Vec::new(); + let mut methods = String::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 @@ -436,10 +436,10 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { if !found { continue; } } - methods = vec!["g".to_string()]; - if manifest.set.is_some() { methods.push("s".to_string()); } else { methods.push("-".to_string()) }; - if manifest.test.is_some() { methods.push("t".to_string()); } else { methods.push("-".to_string()) }; - if manifest.export.is_some() { methods.push("e".to_string()); } else { methods.push("-".to_string()) }; + methods = "g---".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 { @@ -447,7 +447,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { resource.type_name, format!("{:?}", resource.kind), resource.version, - methods.join(""), + methods.clone(), resource.requires.unwrap_or_default(), resource.description.unwrap_or_default() ]); From 7dd02754de3ca76e9feabd4112162b3609c17487 Mon Sep 17 00:00:00 2001 From: Tess Gauthier Date: Wed, 6 Mar 2024 15:39:44 -0500 Subject: [PATCH 3/3] simplify string allocation --- dsc/src/subcommand.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index cb218c6a..9ec327a3 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -400,13 +400,13 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { ResourceSubCommand::List { resource_name, description, tags, format } => { let mut write_table = false; - let mut methods = String::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,7 +442,6 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { if !found { continue; } } - methods = "g---".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"); } @@ -453,7 +452,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option) { resource.type_name, format!("{:?}", resource.kind), resource.version, - methods.clone(), + methods, resource.requires.unwrap_or_default(), resource.description.unwrap_or_default() ]);