Skip to content

Commit ea4029e

Browse files
committed
Merge branch 'release/0.10.0'
2 parents 61bb302 + 047f709 commit ea4029e

5 files changed

Lines changed: 92 additions & 71 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ subprojects {
1414
apply plugin: 'net.ltgt.errorprone'
1515

1616
group = 's10k.tool'
17-
version = '0.9.0'
17+
version = '0.10.0'
1818

1919
repositories {
2020
mavenLocal()

common/src/main/java/s10k/tool/common/util/TableUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ public static void renderTableData(Column[] columns, SequencedCollection<?> data
258258
AsciiTableBuilder atb = AsciiTable.builder();
259259
if (columns != null) {
260260
atb.data(columns, tableData);
261+
} else {
262+
atb.data(tableData);
261263
}
262264
atb.writeTo(out);
263265
out.write(System.lineSeparator().getBytes(Charset.defaultCharset()));

docs/docs/commands/datum/stream/rename.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ s10k datum stream rename -stream=<streamId>
2222

2323
The **order** of the property names is significant, and corresponds to the property _values_
2424
within the datum stream. You can **rename** the property names, but you can **not reorder**
25-
them. Use the `--unordered-names` option when using the [datum stream list](./list.md) command
25+
them. Use the `--unsorted-names` option when using the [datum stream list](./list.md) command
2626
to preserve the physical property name order.
2727

2828
You can **add** new property names at any time, but you can not remove names. When updating

docs/docs/commands/nodes/meta/list.md

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Show metadata matching a search filter.
1010
```
1111
s10k nodes meta list [-filter=<filter>] -node=nodeId[,nodeId...]
1212
[-node=nodeId[,nodeId...]]...
13+
[-mode=<displayMode>]
1314
```
1415

1516
## Options
@@ -20,6 +21,7 @@ s10k nodes meta list [-filter=<filter>] -node=nodeId[,nodeId...]
2021
|:-------|:-------------|:------------|
2122
| `-node=` | `--node-id=` | the node ID(s) to show metadata for |
2223
| `-filter=` | `--filter=` | an optional [metadata filter][metadata-filter] to limit results to |
24+
| `-mode=` | `--display-mode=` | the format to display the data as, one of `CSV`, `JSON`, or `PRETTY`; defaults to `PRETTY` |
2325

2426
</div>
2527

@@ -40,16 +42,15 @@ You can show exactly the metadata for a single node like this:
4042
=== "Output"
4143

4244
```
43-
Property Value
44-
------------------------------------
45-
nodeId 101
46-
created 2025-08-28T23:22:00.237150Z
47-
updated 2025-08-29T05:20:06.322691Z
48-
{
49-
"m" : {
50-
"limit" : 123,
51-
}
52-
}
45+
+---------+-----------------------------+-------------------+
46+
| Node ID | Updated | Metadata |
47+
+---------+-----------------------------+-------------------+
48+
| 101 | 2025-08-30T03:36:06.277076Z | { |
49+
| | | "m" : { |
50+
| | | "limit" : 123 |
51+
| | | } |
52+
| | | } |
53+
+---------+-----------------------------+-------------------+
5354
```
5455

5556
You can show multiple node metadatas by providing multiple `--node-id` options
@@ -68,27 +69,21 @@ You can show multiple node metadatas by providing multiple `--node-id` options
6869
=== "Output"
6970

7071
```
71-
Property Value
72-
------------------------------------
73-
nodeId 101
74-
created 2025-08-28T23:22:00.237150Z
75-
updated 2025-08-29T05:20:06.322691Z
76-
{
77-
"m" : {
78-
"limit" : 123
79-
}
80-
}
81-
82-
Property Value
83-
------------------------------------
84-
nodeId 102
85-
created 2025-08-28T12:22:00.433152Z
86-
updated 2025-08-28T18:11:21.627128Z
87-
{
88-
"m" : {
89-
"limit" : 234
90-
}
91-
}
72+
+---------+-----------------------------+-------------------+
73+
| Node ID | Updated | Metadata |
74+
+---------+-----------------------------+-------------------+
75+
| 101 | 2025-08-30T03:36:06.277076Z | { |
76+
| | | "m" : { |
77+
| | | "limit" : 123 |
78+
| | | } |
79+
| | | } |
80+
+---------+-----------------------------+-------------------+
81+
| 102 | 2025-08-30T03:36:06.277076Z | { |
82+
| | | "m" : { |
83+
| | | "limit" : 234 |
84+
| | | } |
85+
| | | } |
86+
+---------+-----------------------------+-------------------+
9287
```
9388

9489
You can restrict the returned metadata using a [metadata filter][metadata-filter], for example
@@ -103,16 +98,15 @@ to show only the metadata where `limit` is greater than `200`:
10398
=== "Output"
10499

105100
```
106-
Property Value
107-
------------------------------------
108-
nodeId 102
109-
created 2025-08-28T12:22:00.433152Z
110-
updated 2025-08-28T18:11:21.627128Z
111-
{
112-
"m" : {
113-
"limit" : 234
114-
}
115-
}
101+
+---------+-----------------------------+-------------------+
102+
| Node ID | Updated | Metadata |
103+
+---------+-----------------------------+-------------------+
104+
| 102 | 2025-08-30T03:36:06.277076Z | { |
105+
| | | "m" : { |
106+
| | | "limit" : 234 |
107+
| | | } |
108+
| | | } |
109+
+---------+-----------------------------+-------------------+
116110
```
117111

118112

nodes/src/main/java/s10k/tool/nodes/meta/cmd/ListNodeMetadataCmd.java

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package s10k.tool.nodes.meta.cmd;
22

3+
import static com.github.freva.asciitable.HorizontalAlign.LEFT;
4+
import static com.github.freva.asciitable.HorizontalAlign.RIGHT;
35
import static net.solarnetwork.util.StringUtils.commaDelimitedStringFromCollection;
46
import static s10k.tool.common.util.RestUtils.checkSuccess;
5-
import static s10k.tool.common.util.TableUtils.basicTable;
67

8+
import java.io.IOException;
79
import java.util.ArrayList;
810
import java.util.Arrays;
9-
import java.util.LinkedHashMap;
1011
import java.util.List;
11-
import java.util.Map;
1212
import java.util.concurrent.Callable;
1313

1414
import org.springframework.http.MediaType;
@@ -20,11 +20,13 @@
2020
import com.fasterxml.jackson.databind.JsonNode;
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.fasterxml.jackson.databind.ObjectWriter;
23+
import com.github.freva.asciitable.Column;
2324

24-
import net.solarnetwork.domain.datum.GeneralDatumMetadata;
2525
import picocli.CommandLine.Command;
2626
import picocli.CommandLine.Option;
2727
import s10k.tool.common.cmd.BaseSubCmd;
28+
import s10k.tool.common.domain.ResultDisplayMode;
29+
import s10k.tool.common.util.TableUtils;
2830
import s10k.tool.nodes.domain.NodeMetadata;
2931

3032
/**
@@ -34,13 +36,26 @@
3436
@Command(name = "list")
3537
public class ListNodeMetadataCmd extends BaseSubCmd<NodeMetadataCmd> implements Callable<Integer> {
3638

37-
@Option(names = { "-node",
38-
"--node-id" }, description = "a node ID to return metadata for", split = "\\s*,\\s*", splitSynopsisLabel = ",", paramLabel = "nodeId", required = true)
39+
// @formatter:off
40+
41+
@Option(names = { "-node", "--node-id" },
42+
description = "a node ID to return metadata for",
43+
split = "\\s*,\\s*", splitSynopsisLabel = ",",
44+
paramLabel = "nodeId",
45+
required = true)
3946
Long[] nodeIds;
4047

41-
@Option(names = { "-filter", "--filter" }, description = "a metadata filter")
48+
@Option(names = { "-filter", "--filter" },
49+
description = "a metadata filter")
4250
String filter;
4351

52+
@Option(names = { "-mode", "--display-mode" },
53+
description = "how to display the CSV data",
54+
defaultValue = "PRETTY")
55+
ResultDisplayMode displayMode = ResultDisplayMode.PRETTY;
56+
57+
// @formatter:on
58+
4459
/**
4560
* Constructor.
4661
*
@@ -63,36 +78,46 @@ public Integer call() throws Exception {
6378
System.out.println("No metadata matched your criteria.");
6479
return 0;
6580
}
66-
boolean multi = false;
67-
for (NodeMetadata meta : metas) {
68-
if (multi) {
69-
System.out.println("");
70-
} else {
71-
multi = true;
72-
}
73-
Map<String, Object> tableData = new LinkedHashMap<String, Object>(4);
74-
tableData.put("nodeId", meta.nodeId());
75-
if (meta.created() != null) {
76-
tableData.put("created", meta.created());
77-
}
78-
if (meta.updated() != null) {
79-
tableData.put("updated", meta.updated());
80-
}
8181

82-
GeneralDatumMetadata gdm = meta.metadata();
82+
List<?> tableData = (displayMode == ResultDisplayMode.JSON
83+
? metas.stream().map(NodeMetadata::metadata).toList()
84+
: metas.stream().map(m -> metadataRow(m, pretty)).toList());
85+
// @formatter:off
86+
TableUtils.renderTableData(new Column[] {
87+
new Column().header("Node ID").dataAlign(RIGHT),
88+
new Column().header("Updated").dataAlign(LEFT),
89+
new Column().header("Metadata").dataAlign(LEFT),
90+
}, tableData, displayMode, objectMapper, TableUtils.TableDataJsonPrettyPrinter.INSTANCE, System.out);
91+
// @formatter:on
8392

84-
System.out.print(basicTable(tableData, "Property", "Value", false));
85-
if (gdm != null) {
86-
System.out.println(pretty.writeValueAsString(gdm));
87-
}
88-
}
8993
return 0;
9094
} catch (Exception e) {
9195
System.err.println("Error listing node metadata: %s".formatted(e.getMessage()));
9296
}
9397
return 1;
9498
}
9599

100+
/**
101+
* Convert datum stream metadata into a tabular structure.
102+
*
103+
* @param m the metadata to convert
104+
* @param jsonWriter the writer to use for JSON metadata
105+
* @return the metadata data
106+
*/
107+
public static Object[] metadataRow(NodeMetadata m, ObjectWriter jsonWriter) {
108+
try {
109+
// @formatter:off
110+
return new Object[] {
111+
m.nodeId(),
112+
m.updated(),
113+
jsonWriter.writeValueAsString(m.metadata()),
114+
};
115+
// @formatter:on
116+
} catch (IOException e) {
117+
throw new IllegalStateException(e);
118+
}
119+
}
120+
96121
/**
97122
* List node metadata matching a search filter.
98123
*

0 commit comments

Comments
 (0)