tiny.smg.cli.graph
Defined in cli.
API (2)
Actions
Public operations.
Source
Source: tools/smg/src/cli/graph.zig
zig
const std = @import("std");const smg = @import("../root.zig");const exports = smg.exports;const graph_mod = smg.graph;const cli_json = smg.cli.json;const cli_options = smg.cli.options;const cli_output = smg.cli.output;const cli_table = smg.cli.table;pub fn writeNames(allocator: std.mem.Allocator, graph: graph_mod.Graph, center: []const u8, names: []const []const u8, title: []const u8, fmt: []const u8, limit: i64) !u8 { if (std.mem.eql(u8, fmt, "json")) return try cli_json.stringArray(allocator, names); if (std.mem.eql(u8, fmt, "mermaid") or std.mem.eql(u8, fmt, "dot")) { var sub = graph_mod.init(allocator); if (graph_mod.getNode(&graph, center)) |node| try graph_mod.addNode(&sub, node); for (names) |name| if (graph_mod.getNode(&graph, name)) |node| try graph_mod.addNode(&sub, node); for (graph.edges.items) |edge| if (sub.node_index.contains(edge.source) and sub.node_index.contains(edge.target)) try graph_mod.addEdge(&sub, edge); return try write(allocator, sub, fmt); } var out: std.Io.Writer.Allocating = .init(allocator); if (names.len == 0) return try cli_output.writeOutFmt(allocator, "{s}: (none)\n", .{title}); try out.writer.print("{s}:\n", .{title}); const displayed = cli_options.slicedLen(names.len, limit); const columns = [_]cli_table.Column{ .{ .header = "name", .max_width = 72 }, }; var scratch_state = std.heap.ArenaAllocator.init(allocator); defer scratch_state.deinit(); const scratch = scratch_state.allocator(); var rows: std.ArrayList([]const []const u8) = .empty; for (names[0..displayed]) |name| try cli_table.appendRow(scratch, &rows, &.{name}); try cli_table.writeJsonOption(allocator, &out.writer, &columns, rows.items, names.len, "--format json"); return try cli_output.writeOut(out.written());}pub fn write(allocator: std.mem.Allocator, graph: graph_mod.Graph, fmt: []const u8) !u8 { if (std.mem.eql(u8, fmt, "json")) return try cli_output.writeOut(try exports.toJson(allocator, graph, false)); if (std.mem.eql(u8, fmt, "mermaid")) return try cli_output.writeOut(try exports.toMermaid(allocator, graph)); if (std.mem.eql(u8, fmt, "dot")) return try cli_output.writeOut(try exports.toDot(allocator, graph)); return try cli_output.writeOut(try exports.toText(allocator, graph));}Source: tools/smg/src/cli/root.zig:3
zig
pub const graph = @import("graph.zig");Audit
| Definitions | 3 |
|---|---|
| Public names | 3 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |