Skip to content

Commit 17547fb

Browse files
committed
dissect: almost port systemd-dissect to table_print_with_pager()
This doesn't actually port systemd-dissect to table_print_with_pager() but at least rearranges things so that similar behaviour is exposed. The reason it's not ported over 1:1 is that systemd-dissect actually adjusts the JSON output of the table with additional info, and doesn't print the table 1:1 as JSON.
1 parent 16a36b5 commit 17547fb

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

man/systemd-dissect.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@
237237
url="https://systemd.io/DISCOVERABLE_PARTITIONS">Discoverable Partitions Specification</ulink>.</para></listitem>
238238
</varlistentry>
239239

240+
<xi:include href="standard-options.xml" xpointer="no-pager" />
241+
<xi:include href="standard-options.xml" xpointer="no-legend" />
240242
</variablelist>
241243

242244
</refsect1>

src/dissect/dissect.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static const char *arg_target = NULL;
4646
static DissectImageFlags arg_flags = DISSECT_IMAGE_REQUIRE_ROOT|DISSECT_IMAGE_DISCARD_ON_LOOP|DISSECT_IMAGE_RELAX_VAR_CHECK|DISSECT_IMAGE_FSCK;
4747
static VeritySettings arg_verity_settings = VERITY_SETTINGS_DEFAULT;
4848
static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF;
49+
static PagerFlags arg_pager_flags = 0;
50+
static bool arg_legend = true;
4951

5052
STATIC_DESTRUCTOR_REGISTER(arg_verity_settings, verity_settings_done);
5153

@@ -63,6 +65,8 @@ static int help(void) {
6365
"%1$s [OPTIONS...] --copy-to IMAGE [SOURCE] PATH\n\n"
6466
"%5$sDissect a file system OS image.%6$s\n\n"
6567
"%3$sOptions:%4$s\n"
68+
" --no-pager Do not pipe output into a pager\n"
69+
" --no-legend Do not show the headers and footers\n"
6670
" -r --read-only Mount read-only\n"
6771
" --fsck=BOOL Run fsck before mounting\n"
6872
" --mkdir Make mount directory before mounting, if missing\n"
@@ -96,6 +100,8 @@ static int parse_argv(int argc, char *argv[]) {
96100

97101
enum {
98102
ARG_VERSION = 0x100,
103+
ARG_NO_PAGER,
104+
ARG_NO_LEGEND,
99105
ARG_DISCARD,
100106
ARG_FSCK,
101107
ARG_ROOT_HASH,
@@ -108,6 +114,8 @@ static int parse_argv(int argc, char *argv[]) {
108114
static const struct option options[] = {
109115
{ "help", no_argument, NULL, 'h' },
110116
{ "version", no_argument, NULL, ARG_VERSION },
117+
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
118+
{ "no-legend", no_argument, NULL, ARG_NO_LEGEND },
111119
{ "mount", no_argument, NULL, 'm' },
112120
{ "read-only", no_argument, NULL, 'r' },
113121
{ "discard", required_argument, NULL, ARG_DISCARD },
@@ -137,6 +145,14 @@ static int parse_argv(int argc, char *argv[]) {
137145
case ARG_VERSION:
138146
return version();
139147

148+
case ARG_NO_PAGER:
149+
arg_pager_flags |= PAGER_DISABLE;
150+
break;
151+
152+
case ARG_NO_LEGEND:
153+
arg_legend = false;
154+
break;
155+
140156
case 'm':
141157
arg_action = ACTION_MOUNT;
142158
break;
@@ -339,6 +355,9 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
339355
assert(m);
340356
assert(d);
341357

358+
if (arg_json_format_flags & (JSON_FORMAT_OFF|JSON_FORMAT_PRETTY|JSON_FORMAT_PRETTY_AUTO))
359+
(void) pager_open(arg_pager_flags);
360+
342361
if (arg_json_format_flags & JSON_FORMAT_OFF)
343362
printf(" Name: %s\n", basename(arg_image));
344363

@@ -482,7 +501,9 @@ static int action_dissect(DissectedImage *m, LoopDevice *d) {
482501
}
483502

484503
if (arg_json_format_flags & JSON_FORMAT_OFF) {
485-
r = table_print(t, stdout);
504+
(void) table_set_header(t, arg_legend);
505+
506+
r = table_print(t, NULL);
486507
if (r < 0)
487508
return table_log_print_error(r);
488509
} else {

0 commit comments

Comments
 (0)