Skip to content

Commit

Permalink
- use Table class from barrel
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Feb 26, 2024
1 parent d082b17 commit e06b544
Show file tree
Hide file tree
Showing 11 changed files with 628 additions and 491 deletions.
12 changes: 6 additions & 6 deletions client/GlobalOptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,31 @@ namespace snapper
}


TableStyle
Style
GlobalOptions::table_style_value(const ParsedOpts& opts) const
{
ParsedOpts::const_iterator it = opts.find("table-style");
if (it == opts.end())
return TableFormatter::default_style();
return TableFormatter::auto_style();

try
{
unsigned long value = stoul(it->second);

if (value >= Table::numStyles)
if (value >= Table::num_styles)
throw exception();

return (TableStyle)(value);
return (Style)(value);
}
catch (const exception&)
{
string error = sformat(_("Invalid table style '%s'."), it->second.c_str()) + '\n' +
sformat(_("Use an integer number from %d to %d."), 0, Table::numStyles - 1);
sformat(_("Use an integer number from %d to %d."), 0, Table::num_styles - 1);

SN_THROW(OptionsException(error));
}

return TableFormatter::default_style();
return TableFormatter::auto_style();
}


Expand Down
6 changes: 3 additions & 3 deletions client/GlobalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace snapper
bool no_dbus() const { return _no_dbus; }
bool version() const { return _version; }
bool help() const { return _help; }
TableStyle table_style() const { return _table_style; }
Style table_style() const { return _table_style; }
bool abbreviate() const { return _abbreviate; }
OutputFormat output_format() const { return _output_format; }
string separator() const { return _separator; }
Expand All @@ -68,7 +68,7 @@ namespace snapper

void check_options(const ParsedOpts& parsed_opts) const;

TableStyle table_style_value(const ParsedOpts& parsed_opts) const;
Style table_style_value(const ParsedOpts& parsed_opts) const;
OutputFormat output_format_value(const ParsedOpts& parsed_opts) const;
string separator_value(const ParsedOpts& parsed_opts) const;
string config_value(const ParsedOpts& parsed_opts) const;
Expand All @@ -83,7 +83,7 @@ namespace snapper
bool _no_dbus;
bool _version;
bool _help;
TableStyle _table_style;
Style _table_style;
bool _abbreviate;
OutputFormat _output_format;
string _separator;
Expand Down
8 changes: 4 additions & 4 deletions client/cmd-get-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ namespace snapper
};


pair<string, TableAlign>
Cell
header_for(Column column)
{
switch (column)
{
case Column::KEY:
return make_pair(_("Key"), TableAlign::LEFT);
return Cell(_("Key"));

case Column::VALUE:
return make_pair(_("Value"), TableAlign::LEFT);
return Cell(_("Value"));
}

SN_THROW(Exception("invalid column value"));
Expand All @@ -96,7 +96,7 @@ namespace snapper


void
output_table(const vector<Column>& columns, TableStyle style, ProxySnapper* snapper)
output_table(const vector<Column>& columns, Style style, ProxySnapper* snapper)
{
TableFormatter formatter(style);

Expand Down
8 changes: 4 additions & 4 deletions client/cmd-list-configs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ namespace snapper
};


pair<string, TableAlign>
Cell
header_for(Column column)
{
switch (column)
{
case Column::CONFIG:
return make_pair(_("Config"), TableAlign::LEFT);
return Cell(_("Config"));

case Column::SUBVOLUME:
return make_pair(_("Subvolume"), TableAlign::LEFT);
return Cell(_("Subvolume"));
}

SN_THROW(Exception("invalid column value"));
Expand All @@ -95,7 +95,7 @@ namespace snapper


void
output_table(const vector<Column>& columns, TableStyle style, ProxySnappers* snappers)
output_table(const vector<Column>& columns, Style style, ProxySnappers* snappers)
{
TableFormatter formatter(style);

Expand Down
43 changes: 22 additions & 21 deletions client/cmd-list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,64 +333,64 @@ namespace snapper
}


pair<string, TableAlign>
Cell
header_for(ListMode list_mode, Column column)
{
switch (column)
{
case Column::CONFIG:
return make_pair(_("Config"), TableAlign::LEFT);
return Cell(_("Config"));

case Column::SUBVOLUME:
return make_pair(_("Subvolume"), TableAlign::LEFT);
return Cell(_("Subvolume"));

case Column::NUMBER:
if (list_mode != ListMode::PRE_POST)
return make_pair(_("#"), TableAlign::RIGHT);
return Cell(_("#"), Id::NUMBER, Align::RIGHT);
else
return make_pair(_("Pre #"), TableAlign::RIGHT);
return Cell(_("Pre #"), Id::NUMBER, Align::RIGHT);

case Column::DEFAULT:
return make_pair(_("Default"), TableAlign::LEFT);
return Cell(_("Default"));

case Column::ACTIVE:
return make_pair(_("Active"), TableAlign::LEFT);
return Cell(_("Active"));

case Column::TYPE:
return make_pair(_("Type"), TableAlign::LEFT);
return Cell(_("Type"), Id::TYPE);

case Column::DATE:
if (list_mode != ListMode::PRE_POST)
return make_pair(_("Date"), TableAlign::LEFT);
return Cell(_("Date"));
else
return make_pair(_("Pre Date"), TableAlign::LEFT);
return Cell(_("Pre Date"));

case Column::USER:
return make_pair(_("User"), TableAlign::LEFT);
return Cell(_("User"));

case Column::USED_SPACE:
return make_pair(_("Used Space"), TableAlign::RIGHT);;
return Cell(_("Used Space"), Align::RIGHT);;

case Column::CLEANUP:
return make_pair(_("Cleanup"), TableAlign::LEFT);
return Cell(_("Cleanup"));

case Column::DESCRIPTION:
return make_pair(_("Description"), TableAlign::LEFT);
return Cell(_("Description"), Id::DESCRIPTION);

case Column::USERDATA:
return make_pair(_("Userdata"), TableAlign::LEFT);
return Cell(_("Userdata"), Id::USERDATA);

case Column::PRE_NUMBER:
return make_pair(_("Pre #"), TableAlign::RIGHT);
return Cell(_("Pre #"), Id::PRE_NUMBER, Align::RIGHT);

case Column::POST_NUMBER:
return make_pair(_("Post #"), TableAlign::RIGHT);
return Cell(_("Post #"), Id::POST_NUMBER, Align::RIGHT);

case Column::POST_DATE:
return make_pair(_("Post Date"), TableAlign::LEFT);
return Cell(_("Post Date"));

case Column::READ_ONLY:
return make_pair(_("Read-Only"), TableAlign::LEFT);
return Cell(_("Read-Only"));
}

SN_THROW(Exception("invalid column value"));
Expand Down Expand Up @@ -614,8 +614,9 @@ namespace snapper
continue;

formatter.header().push_back(header_for(list_mode, column));
formatter.abbrev().push_back(global_options.abbreviate() &&
column == Column::DESCRIPTION);

if (global_options.abbreviate())
formatter.abbrev().push_back(Id::DESCRIPTION);
}

for (const ProxySnapshot& snapshot : output_helper.snapshots)
Expand Down
Loading

0 comments on commit e06b544

Please sign in to comment.