Skip to content

Commit

Permalink
feat: allow config ls to return JSON (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored Oct 17, 2024
1 parent 1bd50a8 commit 86aa214
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/cli/config/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ConfigLs {
.into_iter()
.map(|s| serde_json::Value::String(s.to_string()))
.collect::<Vec<serde_json::Value>>();
item.insert("plugins".to_string(), serde_json::Value::Array(plugins));
item.insert("tools".to_string(), serde_json::Value::Array(plugins));

item
})
Expand All @@ -74,7 +74,7 @@ impl ConfigLs {
}
}

fn format_plugin_cell(s: String) -> String {
fn format_tools_cell(s: String) -> String {
match s.is_empty() {
true => style("(none)").italic().dim().to_string(),
false => style(s).dim().to_string(),
Expand All @@ -85,16 +85,16 @@ fn format_plugin_cell(s: String) -> String {
#[tabled(rename_all = "PascalCase")]
struct Row {
path: String,
plugins: String,
tools: String,
}

impl From<&dyn ConfigFile> for Row {
fn from(cf: &dyn ConfigFile) -> Self {
let path = display_path(cf.get_path());
let ts = cf.to_tool_request_set().unwrap();
let plugins = ts.list_plugins().into_iter().join(", ");
let plugins = format_plugin_cell(plugins);
Self { path, plugins }
let tools = format_tools_cell(plugins);
Self { path, tools }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ expression: output
[
{
"path": "~/cwd/.test-tool-versions",
"plugins": [
"tools": [
"tiny"
]
},
{
"path": "~/.test-tool-versions",
"plugins": [
"tools": [
"tiny",
"dummy"
]
},
{
"path": "~/config/config.toml",
"plugins": []
"tools": []
}
]

0 comments on commit 86aa214

Please sign in to comment.