Skip to content

Commit 2f4670c

Browse files
authored
Merge pull request #314 from tgauth/add-methods-table-view
add methods column to table view
2 parents 01b7cd4 + 1b52b60 commit 2f4670c

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

Diff for: dsc/src/subcommand.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,15 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
322322
ResourceSubCommand::List { resource_name, description, tags, format } => {
323323

324324
let mut write_table = false;
325-
let mut table = Table::new(&["Type", "Version", "Requires", "Description"]);
325+
let mut methods: Vec<String> = Vec::new();
326+
let mut table = Table::new(&["Type", "Version", "Methods", "Requires", "Description"]);
326327
if format.is_none() && atty::is(Stream::Stdout) {
327-
// write as table if fornat is not specified and interactive
328+
// write as table if format is not specified and interactive
328329
write_table = true;
329330
}
330331
for resource in dsc.list_available_resources(&resource_name.clone().unwrap_or_default()) {
331-
// if description is specified, skip if resource description does not contain it
332-
if description.is_some() || tags.is_some() {
332+
// if description, tags, or write_table is specified, pull resource manifest if it exists
333+
if description.is_some() || tags.is_some() || write_table {
333334
let Some(ref resource_manifest) = resource.manifest else {
334335
continue;
335336
};
@@ -341,16 +342,15 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
341342
}
342343
};
343344

345+
// if description is specified, skip if resource description does not contain it
344346
if description.is_some() &&
345347
(manifest.description.is_none() | !manifest.description.unwrap_or_default().to_lowercase().contains(&description.as_ref().unwrap_or(&String::new()).to_lowercase())) {
346348
continue;
347349
}
348350

349351
// if tags is specified, skip if resource tags do not contain the tags
350352
if let Some(tags) = tags {
351-
let Some(manifest_tags) = manifest.tags else {
352-
continue;
353-
};
353+
let Some(manifest_tags) = manifest.tags else { continue; };
354354

355355
let mut found = false;
356356
for tag_to_find in tags {
@@ -361,16 +361,20 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
361361
}
362362
}
363363
}
364-
if !found {
365-
continue;
366-
}
364+
if !found { continue; }
367365
}
366+
367+
methods = vec!["get".to_string()];
368+
if manifest.set.is_some() { methods.push("set".to_string()); }
369+
if manifest.test.is_some() { methods.push("test".to_string()); }
370+
if manifest.export.is_some() { methods.push("export".to_string()); }
368371
}
369372

370373
if write_table {
371374
table.add_row(vec![
372375
resource.type_name,
373376
resource.version,
377+
methods.join(", "),
374378
resource.requires.unwrap_or_default(),
375379
resource.description.unwrap_or_default()
376380
]);
@@ -386,9 +390,7 @@ pub fn resource(subcommand: &ResourceSubCommand, stdin: &Option<String>) {
386390
};
387391
write_output(&json, format);
388392
// insert newline separating instances if writing to console
389-
if atty::is(Stream::Stdout) {
390-
println!();
391-
}
393+
if atty::is(Stream::Stdout) { println!(); }
392394
}
393395
}
394396

Diff for: dsc_lib/src/configure/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ pub enum ErrorAction {
4545
///
4646
/// # Panics
4747
///
48-
/// Doesn't panic because there is a match/Some check before unwrap(); false positive.
48+
/// Doesn't panic because there is a match/Some check before `unwrap()`; false positive.
4949
///
5050
/// # Errors
5151
///
5252
/// This function will return an error if the underlying resource fails.
5353
pub fn add_resource_export_results_to_configuration(resource: &DscResource, provider_resource: Option<&DscResource>, conf: &mut Configuration, input: &str) -> Result<(), DscError> {
54-
54+
5555
let export_result = match provider_resource {
5656
Some(_) => provider_resource.unwrap().export(input)?,
5757
_ => resource.export(input)?

0 commit comments

Comments
 (0)