mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 12:31:06 +01:00
added -D to alter sort order to descending order (default: ascending)
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
## Features to be implemented
|
## Features to be implemented
|
||||||
|
|
||||||
- ability to change sort order (ascending vs descending)
|
|
||||||
|
|
||||||
- sorting by: numerical, time, duration, string(default)
|
- sorting by: numerical, time, duration, string(default)
|
||||||
|
|
||||||
- add output modes yaml and csv
|
- add output modes yaml and csv
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
||||||
rootCmd.PersistentFlags().StringVarP(&lib.Separator, "separator", "s", lib.DefaultSeparator, "Custom field separator")
|
rootCmd.PersistentFlags().StringVarP(&lib.Separator, "separator", "s", lib.DefaultSeparator, "Custom field separator")
|
||||||
rootCmd.PersistentFlags().StringVarP(&lib.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
rootCmd.PersistentFlags().StringVarP(&lib.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||||
|
|
||||||
|
// sort options
|
||||||
rootCmd.PersistentFlags().IntVarP(&lib.SortByColumn, "sort-by", "k", 0, "Sort by column (default: 1)")
|
rootCmd.PersistentFlags().IntVarP(&lib.SortByColumn, "sort-by", "k", 0, "Sort by column (default: 1)")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&lib.SortDescending, "sort-desc", "D", false, "Sort in descending order (default: ascending)")
|
||||||
|
|
||||||
// output flags, only 1 allowed, hidden, since just short cuts
|
// output flags, only 1 allowed, hidden, since just short cuts
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagExtended, "extended", "X", false, "Enable extended output")
|
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagExtended, "extended", "X", false, "Enable extended output")
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ SYNOPSIS
|
|||||||
-O, --orgtbl Enable org-mode table output
|
-O, --orgtbl Enable org-mode table output
|
||||||
-s, --separator string Custom field separator
|
-s, --separator string Custom field separator
|
||||||
-k, --sort-by int Sort by column (default: 1)
|
-k, --sort-by int Sort by column (default: 1)
|
||||||
|
-D, --sort-desc Sort in descending order (default: ascending)
|
||||||
-v, --version Print program version
|
-v, --version Print program version
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@@ -78,7 +79,8 @@ DESCRIPTION
|
|||||||
|
|
||||||
Use the -k option to specify by which column to sort the tabular data
|
Use the -k option to specify by which column to sort the tabular data
|
||||||
(as in GNU sort(1)). The default sort column is the first one. To
|
(as in GNU sort(1)). The default sort column is the first one. To
|
||||||
disable sorting at all, supply 0 (Zero) to -k.
|
disable sorting at all, supply 0 (Zero) to -k. The default sort order is
|
||||||
|
ascending. You can change this to descending order using the option -D.
|
||||||
|
|
||||||
Finally the -d option enables debugging output which is mostly useful
|
Finally the -d option enables debugging output which is mostly useful
|
||||||
for the developer.
|
for the developer.
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ var (
|
|||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
SortByColumn int
|
SortByColumn int
|
||||||
|
SortDescending bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// contains a whole parsed table
|
// contains a whole parsed table
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ func sortTable(data *Tabdata, col int) {
|
|||||||
|
|
||||||
// actual sorting
|
// actual sorting
|
||||||
sort.SliceStable(data.entries, func(i, j int) bool {
|
sort.SliceStable(data.entries, func(i, j int) bool {
|
||||||
|
if SortDescending {
|
||||||
|
return data.entries[i][col] > data.entries[j][col]
|
||||||
|
}
|
||||||
return data.entries[i][col] < data.entries[j][col]
|
return data.entries[i][col] < data.entries[j][col]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ tablizer \- Manipulate tabular output of other programs
|
|||||||
\& \-O, \-\-orgtbl Enable org\-mode table output
|
\& \-O, \-\-orgtbl Enable org\-mode table output
|
||||||
\& \-s, \-\-separator string Custom field separator
|
\& \-s, \-\-separator string Custom field separator
|
||||||
\& \-k, \-\-sort\-by int Sort by column (default: 1)
|
\& \-k, \-\-sort\-by int Sort by column (default: 1)
|
||||||
|
\& \-D, \-\-sort\-desc Sort in descending order (default: ascending)
|
||||||
\& \-v, \-\-version Print program version
|
\& \-v, \-\-version Print program version
|
||||||
.Ve
|
.Ve
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
@@ -225,7 +226,9 @@ highlighted. You can disable this behavior with the \fB\-N\fR option.
|
|||||||
.PP
|
.PP
|
||||||
Use the \fB\-k\fR option to specify by which column to sort the tabular
|
Use the \fB\-k\fR option to specify by which column to sort the tabular
|
||||||
data (as in \s-1GNU\s0 \fBsort\fR\|(1)). The default sort column is the first one. To
|
data (as in \s-1GNU\s0 \fBsort\fR\|(1)). The default sort column is the first one. To
|
||||||
disable sorting at all, supply 0 (Zero) to \-k.
|
disable sorting at all, supply 0 (Zero) to \-k. The default sort order
|
||||||
|
is ascending. You can change this to descending order using the option
|
||||||
|
\&\fB\-D\fR.
|
||||||
.PP
|
.PP
|
||||||
Finally the \fB\-d\fR option enables debugging output which is mostly
|
Finally the \fB\-d\fR option enables debugging output which is mostly
|
||||||
useful for the developer.
|
useful for the developer.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
-O, --orgtbl Enable org-mode table output
|
-O, --orgtbl Enable org-mode table output
|
||||||
-s, --separator string Custom field separator
|
-s, --separator string Custom field separator
|
||||||
-k, --sort-by int Sort by column (default: 1)
|
-k, --sort-by int Sort by column (default: 1)
|
||||||
|
-D, --sort-desc Sort in descending order (default: ascending)
|
||||||
-v, --version Print program version
|
-v, --version Print program version
|
||||||
|
|
||||||
|
|
||||||
@@ -81,7 +82,9 @@ highlighted. You can disable this behavior with the B<-N> option.
|
|||||||
|
|
||||||
Use the B<-k> option to specify by which column to sort the tabular
|
Use the B<-k> option to specify by which column to sort the tabular
|
||||||
data (as in GNU sort(1)). The default sort column is the first one. To
|
data (as in GNU sort(1)). The default sort column is the first one. To
|
||||||
disable sorting at all, supply 0 (Zero) to -k.
|
disable sorting at all, supply 0 (Zero) to -k. The default sort order
|
||||||
|
is ascending. You can change this to descending order using the option
|
||||||
|
B<-D>.
|
||||||
|
|
||||||
Finally the B<-d> option enables debugging output which is mostly
|
Finally the B<-d> option enables debugging output which is mostly
|
||||||
useful for the developer.
|
useful for the developer.
|
||||||
|
|||||||
Reference in New Issue
Block a user