Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package gitopper for openSUSE:Factory checked in at 2024-09-16 17:41:53 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/gitopper (Old) and /work/SRC/openSUSE:Factory/.gitopper.new.29891 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "gitopper" Mon Sep 16 17:41:53 2024 rev:2 rq:1201144 version:0.0.20 Changes: -------- --- /work/SRC/openSUSE:Factory/gitopper/gitopper.changes 2024-09-09 14:44:34.927048952 +0200 +++ /work/SRC/openSUSE:Factory/.gitopper.new.29891/gitopper.changes 2024-09-16 17:42:49.100418440 +0200 @@ -1,0 +2,31 @@ +Sat Sep 14 14:23:28 UTC 2024 - [email protected] + +- Update to version 0.0.20: + * Enable unit after mounting. (#81) + +------------------------------------------------------------------- +Sat Sep 14 14:22:30 UTC 2024 - [email protected] + +- Update to version 0.0.19: + * The `Action` set might be `reload` and that would not start the + unit. (#80) + +------------------------------------------------------------------- +Sat Sep 14 14:20:46 UTC 2024 - [email protected] + +- Update to version 0.0.18: + * There is a bug with paths longer than 80 characters. When + running `git pull --stat` for changes with these long paths. + You get a truncated path: (#79) + +------------------------------------------------------------------- +Sat Sep 14 14:15:59 UTC 2024 - [email protected] + +- Update to version 0.0.17: + * Clear errors (#78) + * Use tabwriter from the standard library to print aligned text. + (#77) + * Remount files (#76) + * ci doesnt compile; remove + +------------------------------------------------------------------- Old: ---- gitopper-0.0.16.obscpio New: ---- gitopper-0.0.20.obscpio ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ gitopper.spec ++++++ --- /var/tmp/diff_new_pack.K1nacx/_old 2024-09-16 17:42:50.244465730 +0200 +++ /var/tmp/diff_new_pack.K1nacx/_new 2024-09-16 17:42:50.244465730 +0200 @@ -19,7 +19,7 @@ %define __arch_install_post export NO_BRP_STRIP_DEBUG=true Name: gitopper -Version: 0.0.16 +Version: 0.0.20 Release: 0 Summary: Gitops for non-Kubernetes folks License: Apache-2.0 ++++++ _service ++++++ --- /var/tmp/diff_new_pack.K1nacx/_old 2024-09-16 17:42:50.276467052 +0200 +++ /var/tmp/diff_new_pack.K1nacx/_new 2024-09-16 17:42:50.280467218 +0200 @@ -3,7 +3,7 @@ <param name="url">https://github.com/miekg/gitopper</param> <param name="scm">git</param> <param name="exclude">.git</param> - <param name="revision">v0.0.16</param> + <param name="revision">v0.0.20</param> <param name="versionformat">@PARENT_TAG@</param> <param name="changesgenerate">enable</param> <param name="versionrewrite-pattern">v(.*)</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.K1nacx/_old 2024-09-16 17:42:50.300468044 +0200 +++ /var/tmp/diff_new_pack.K1nacx/_new 2024-09-16 17:42:50.300468044 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/miekg/gitopper</param> - <param name="changesrevision">b6ddcfaa593f8a7509647acee91b6d6e17dded9a</param></service></servicedata> + <param name="changesrevision">7b7d91e6be2f6a2a60c73f00a7e053d86804ef6d</param></service></servicedata> (No newline at EOF) ++++++ gitopper-0.0.16.obscpio -> gitopper-0.0.20.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/.github/workflows/ci.yml new/gitopper-0.0.20/.github/workflows/ci.yml --- old/gitopper-0.0.16/.github/workflows/ci.yml 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/.github/workflows/ci.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,25 +0,0 @@ -name: CI -on: - push: - tags: - - 'v*' - -jobs: - build: - name: Create Release - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - run: git fetch --force --tags - - uses: actions/setup-go@v4 - with: - go-version: '1.22' - - uses: goreleaser/goreleaser-action@v5 - with: - version: '1.22' - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/.github/workflows/codeql-analysis.yml new/gitopper-0.0.20/.github/workflows/codeql-analysis.yml --- old/gitopper-0.0.16/.github/workflows/codeql-analysis.yml 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/.github/workflows/codeql-analysis.yml 1970-01-01 01:00:00.000000000 +0100 @@ -1,32 +0,0 @@ -name: "Code scanning - action" - -on: - push: - branches: [master, ] - pull_request: - branches: [master] - schedule: - - cron: '0 23 * * 5' - -jobs: - CodeQL-Build: - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - run: git checkout HEAD^2 - if: ${{ github.event_name == 'pull_request' }} - - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/cmd/gitopperctl/main.go new/gitopper-0.0.20/cmd/gitopperctl/main.go --- old/gitopper-0.0.16/cmd/gitopperctl/main.go 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/cmd/gitopperctl/main.go 2024-08-27 07:17:27.000000000 +0200 @@ -3,11 +3,13 @@ import ( "encoding/json" "fmt" + "io" "os" + "strconv" "strings" + "text/tabwriter" "github.com/miekg/gitopper/proto" - "github.com/rodaine/table" "github.com/urfave/cli/v2" "go.science.ru.nl/log" ) @@ -151,6 +153,10 @@ return err } +func tblPrint(writer io.Writer, line []string) { + fmt.Fprintln(writer, strings.Join(line, "\t")) +} + func cmdService(ctx *cli.Context) error { at, err := atMachine(ctx) if err != nil { @@ -174,11 +180,13 @@ fmt.Print(string(body)) return nil } - tbl := table.New("#", "SERVICE", "HASH", "STATE", "INFO", "SINCE") + tbl := new(tabwriter.Writer) + tbl.Init(os.Stdout, 0, 8, 1, ' ', 0) + tblPrint(tbl, []string{"#", "SERVICE", "HASH", "STATE", "INFO", "SINCE"}) for i, ls := range ls.ListServices { - tbl.AddRow(i, ls.Service, ls.Hash, ls.State, ls.StateInfo, ls.StateChange) + tblPrint(tbl, []string{strconv.FormatInt(int64(i), 10), ls.Service, ls.Hash, ls.State, ls.StateInfo, ls.StateChange}) } - tbl.Print() + _ = tbl.Flush() return nil } @@ -199,10 +207,12 @@ fmt.Print(string(body)) return nil } - tbl := table.New("#", "MACHINE", "ACTUAL") + tbl := new(tabwriter.Writer) + tbl.Init(os.Stdout, 0, 8, 1, ' ', 0) + tblPrint(tbl, []string{"#", "MACHINE", "ACTUAL"}) for i, m := range lm.ListMachines { - tbl.AddRow(i, m.Machine, m.Actual) + tblPrint(tbl, []string{strconv.FormatInt(int64(i), 10), m.Machine, m.Actual}) } - tbl.Print() + _ = tbl.Flush() return nil } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/gitcmd/diffstat.go new/gitopper-0.0.20/gitcmd/diffstat.go --- old/gitopper-0.0.16/gitcmd/diffstat.go 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/gitcmd/diffstat.go 2024-08-27 07:17:27.000000000 +0200 @@ -28,11 +28,9 @@ // bunch of lines usually < 1000. So it's not too bad. for scanner.Scan() { text := scanner.Text() - if strings.HasPrefix(text, " ") && strings.Contains(text, " | ") { - for _, d := range g.dirs { - if strings.Contains(text, d) { - return true - } + for _, d := range g.dirs { + if strings.Contains(text, d) { + return true } } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/gitcmd/git.go new/gitopper-0.0.20/gitcmd/git.go --- old/gitopper-0.0.16/gitcmd/git.go 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/gitcmd/git.go 2024-08-27 07:17:27.000000000 +0200 @@ -120,10 +120,16 @@ g.cwd = g.mount defer func() { g.cwd = "" }() - out, err := g.run("pull", "--stat", "origin", g.branch) + if _, err := g.run("fetch"); err != nil { + return false, err + } + out, err := g.run("diff", "--stat=4096", "--name-only", g.branch, fmt.Sprintf("origin/%s", g.branch)) if err != nil { return false, err } + if _, err := g.run("merge"); err != nil { + return false, err + } return g.OfInterest(out), nil } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/main.go new/gitopper-0.0.20/main.go --- old/gitopper-0.0.16/main.go 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/main.go 2024-08-27 07:17:27.000000000 +0200 @@ -261,11 +261,6 @@ log.Fatalf("Service %q, error installing package %q: %s", s.Service, s.Package, err) } } - if strings.Contains(s.Service, "@") { - if err := s.enable(); err != nil { - log.Fatalf("Service %q, error enabling instance template: %s", s.Service, err) - } - } // Initial checkout - if needed. err := gc.Checkout() @@ -284,17 +279,26 @@ s.SetState(StateBroken, fmt.Sprintf("error setting up bind mounts repo %q: %s", s.Upstream, err)) continue } + if strings.Contains(s.Service, "@") { + if err := s.enable(); err != nil { + log.Fatalf("Service %q, error enabling instance template: %s", s.Service, err) + } + } // Restart any services as they see new files in their bindmounts. Do this here, because we can't be // sure there is an update to a newer commit that would also kick off a restart. if mounts > 0 { if rerr := s.reload(); rerr != nil { log.Warningf("Service %q, error running systemctl daemon-reload: %s", s.Service, rerr) s.SetState(StateBroken, fmt.Sprintf("error running systemctl daemon-reload %q: %s", s.Upstream, rerr)) - } else if err := s.systemctl(); err != nil { - log.Warningf("Service %q, error running systemctl: %s", s.Service, err) - s.SetState(StateBroken, fmt.Sprintf("error running systemctl %q: %s", s.Upstream, err)) + } else if err := s.start(); err != nil { + log.Warningf("Service %q, error running systemctl start: %s", s.Service, err) + s.SetState(StateBroken, fmt.Sprintf("error running systemctl start %q: %s", s.Upstream, err)) // no continue; maybe git pull will make this work later + } else { + s.SetState(StateOK, "") } + } else { + s.SetState(StateOK, "") } workerWG.Add(1) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/gitopper-0.0.16/server.go new/gitopper-0.0.20/server.go --- old/gitopper-0.0.16/server.go 2024-08-03 07:42:41.000000000 +0200 +++ new/gitopper-0.0.20/server.go 2024-08-27 07:17:27.000000000 +0200 @@ -177,6 +177,11 @@ s.SetState(StateDiff, fmt.Sprintf("error rolling back %q to %q: %s", s.Upstream, info, err)) continue } + if _, err := s.bindmount(); err != nil { + log.Warningf("Service %q, error setting up bind mounts for %q: %s", s.Service, s.Upstream, err) + s.SetState(StateBroken, fmt.Sprintf("error setting up bind mounts repo %q: %s", s.Upstream, err)) + continue + } if rerr := s.reload(); rerr != nil { log.Warningf("Service %q, error running systemctl daemon-reload: %s", s.Service, rerr) s.SetState(StateBroken, fmt.Sprintf("error running systemctl daemon-reload %q: %s", s.Upstream, rerr)) @@ -211,6 +216,11 @@ state, info = s.State() s.SetState(state, info) + if _, err := s.bindmount(); err != nil { + log.Warningf("Service %q, error setting up bind mounts for %q: %s", s.Service, s.Upstream, err) + s.SetState(StateBroken, fmt.Sprintf("error setting up bind mounts repo %q: %s", s.Upstream, err)) + continue + } log.Infof("Service %q, diff in repo %q, pinging it", s.Service, s.Upstream) if rerr := s.reload(); rerr != nil { log.Warningf("Service %q, error running systemctl daemon-reload: %s", s.Service, rerr) @@ -221,6 +231,7 @@ s.SetState(StateBroken, fmt.Sprintf("error running systemctl %q: %s", s.Upstream, err)) continue } + s.SetState(StateOK, "") } } @@ -248,6 +259,13 @@ return cmd.Run() } +func (s *Service) start() error { + ctx := context.TODO() + cmd := exec.CommandContext(ctx, "systemctl", "start", s.Service) + log.Infof("running %v", cmd.Args) + return cmd.Run() +} + // Boot returns the start time of the service. If that isn't available because there isn't a Service in s, then we // return the kernel's boot time (i.e. when the system we started). func (s *Service) SetBoot() { @@ -320,8 +338,24 @@ } if ok, err := mountinfo.Mounted(d.Local); err == nil && ok { - log.Infof("%s %q is already mounted", logtype, d.Local) - continue + if d.File == true { + log.Infof("%s %q is already mounted, unmounting", logtype, d.Local) + ctx := context.TODO() + cmd := exec.CommandContext(ctx, "umount", d.Local) + log.Infof("running %v", cmd.Args) + err := cmd.Run() + if err != nil { + if exitError, ok := err.(*exec.ExitError); ok { + if e := exitError.ExitCode(); e != 0 { + return 0, fmt.Errorf("failed to umount %q, exit code %d", d.Local, e) + } + } + return 0, fmt.Errorf("failed to umount %q: %s", d.Local, err) + } + } else { + log.Infof("%s %q is already mounted", logtype, d.Local) + continue + } } ctx := context.TODO() ++++++ gitopper.obsinfo ++++++ --- /var/tmp/diff_new_pack.K1nacx/_old 2024-09-16 17:42:50.464474824 +0200 +++ /var/tmp/diff_new_pack.K1nacx/_new 2024-09-16 17:42:50.468474989 +0200 @@ -1,5 +1,5 @@ name: gitopper -version: 0.0.16 -mtime: 1722663761 -commit: b6ddcfaa593f8a7509647acee91b6d6e17dded9a +version: 0.0.20 +mtime: 1724735847 +commit: 7b7d91e6be2f6a2a60c73f00a7e053d86804ef6d ++++++ vendor.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/rodaine/table/license new/vendor/github.com/rodaine/table/license --- old/vendor/github.com/rodaine/table/license 2024-08-12 07:46:41.000000000 +0200 +++ new/vendor/github.com/rodaine/table/license 1970-01-01 01:00:00.000000000 +0100 @@ -1,9 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Chris Roche ([email protected]) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/rodaine/table/readme.md new/vendor/github.com/rodaine/table/readme.md --- old/vendor/github.com/rodaine/table/readme.md 2024-08-12 07:46:41.000000000 +0200 +++ new/vendor/github.com/rodaine/table/readme.md 1970-01-01 01:00:00.000000000 +0100 @@ -1,57 +0,0 @@ -# table <br/> [](https://godoc.org/github.com/rodaine/table) [](https://travis-ci.org/rodaine/table) - - - -Package table provides a convenient way to generate tabular output of any data, primarily useful for CLI tools. - -## Features - -- Accepts all data types (`string`, `int`, `interface{}`, everything!) and will use the `String() string` method of a type if available. -- Can specify custom formatting for the header and first column cells for better readability. -- Columns are left-aligned and sized to fit the data, with customizable padding. -- The printed output can be sent to any `io.Writer`, defaulting to `os.Stdout`. -- Built to an interface, so you can roll your own `Table` implementation. -- Works well with ANSI colors ([fatih/color](https://github.com/fatih/color) in the example)! -- Can provide a custom `WidthFunc` to accomodate multi- and zero-width characters (such as [runewidth](https://github.com/mattn/go-runewidth)) - -## Usage - -**Download the package:** - -```sh -go get github.com/rodaine/table -``` - -**Example:** - -```go -package main - -import ( - "fmt" - "strings" - - "github.com/fatih/color" - "github.com/rodaine/table" -) - -func main() { - headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc() - columnFmt := color.New(color.FgYellow).SprintfFunc() - - tbl := table.New("ID", "Name", "Score", "Added") - tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) - - for _, widget := range getWidgets() { - tbl.AddRow(widget.ID, widget.Name, widget.Cost, widget.Added) - } - - tbl.Print() -} -``` - -_Consult the [documentation](https://godoc.org/github.com/rodaine/table) for further examples and usage information_ - -## License - -table is released under the MIT License (Expat). See the [full license](https://github.com/rodaine/table/blob/master/license). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/github.com/rodaine/table/table.go new/vendor/github.com/rodaine/table/table.go --- old/vendor/github.com/rodaine/table/table.go 2024-08-12 07:46:41.000000000 +0200 +++ new/vendor/github.com/rodaine/table/table.go 1970-01-01 01:00:00.000000000 +0100 @@ -1,267 +0,0 @@ -// Package table provides a convenient way to generate tabular output of any -// data, primarily useful for CLI tools. -// -// Columns are left-aligned and padded to accomodate the largest cell in that -// column. -// -// Source: https://github.com/rodaine/table -// -// table.DefaultHeaderFormatter = func(format string, vals ...interface{}) string { -// return strings.ToUpper(fmt.Sprintf(format, vals...)) -// } -// -// tbl := table.New("ID", "Name", "Cost ($)") -// -// for _, widget := range Widgets { -// tbl.AddRow(widget.ID, widget.Name, widget.Cost) -// } -// -// tbl.Print() -// -// // Output: -// // ID NAME COST ($) -// // 1 Foobar 1.23 -// // 2 Fizzbuzz 4.56 -// // 3 Gizmo 78.90 -package table - -import ( - "fmt" - "io" - "os" - "strings" - "unicode/utf8" -) - -// These are the default properties for all Tables created from this package -// and can be modified. -var ( - // DefaultPadding specifies the number of spaces between columns in a table. - DefaultPadding = 2 - - // DefaultWriter specifies the output io.Writer for the Table.Print method. - DefaultWriter io.Writer = os.Stdout - - // DefaultHeaderFormatter specifies the default Formatter for the table header. - DefaultHeaderFormatter Formatter - - // DefaultFirstColumnFormatter specifies the default Formatter for the first column cells. - DefaultFirstColumnFormatter Formatter - - // DefaultWidthFunc specifies the default WidthFunc for calculating column widths - DefaultWidthFunc WidthFunc = utf8.RuneCountInString -) - -// Formatter functions expose a fmt.Sprintf signature that can be used to modify -// the display of the text in either the header or first column of a Table. -// The formatter should not change the width of original text as printed since -// column widths are calculated pre-formatting (though this issue can be mitigated -// with increased padding). -// -// tbl.WithHeaderFormatter(func(format string, vals ...interface{}) string { -// return strings.ToUpper(fmt.Sprintf(format, vals...)) -// }) -// -// A good use case for formatters is to use ANSI escape codes to color the cells -// for a nicer interface. The package color (https://github.com/fatih/color) makes -// it easy to generate these automatically: http://godoc.org/github.com/fatih/color#Color.SprintfFunc -type Formatter func(string, ...interface{}) string - -// A WidthFunc calculates the width of a string. By default, the number of runes -// is used but this may not be appropriate for certain character sets. The -// package runewidth (https://github.com/mattn/go-runewidth) could be used to -// accomodate multi-cell characters (such as emoji or CJK characters). -type WidthFunc func(string) int - -// Table describes the interface for building up a tabular representation of data. -// It exposes fluent/chainable methods for convenient table building. -// -// WithHeaderFormatter and WithFirstColumnFormatter sets the Formatter for the -// header and first column, respectively. If nil is passed in (the default), no -// formatting will be applied. -// -// New("foo", "bar").WithFirstColumnFormatter(func(f string, v ...interface{}) string { -// return strings.ToUpper(fmt.Sprintf(f, v...)) -// }) -// -// WithPadding specifies the minimum padding between cells in a row and defaults -// to DefaultPadding. Padding values less than or equal to zero apply no extra -// padding between the columns. -// -// New("foo", "bar").WithPadding(3) -// -// WithWriter modifies the writer which Print outputs to, defaulting to DefaultWriter -// when instantiated. If nil is passed, os.Stdout will be used. -// -// New("foo", "bar").WithWriter(os.Stderr) -// -// WithWidthFunc sets the function used to calculate the width of the string in -// a column. By default, the number of utf8 runes in the string is used. -// -// AddRow adds another row of data to the table. Any values can be passed in and -// will be output as its string representation as described in the fmt standard -// package. Rows can have less cells than the total number of columns in the table; -// subsequent cells will be rendered empty. Rows with more cells than the total -// number of columns will be truncated. References to the data are not held, so -// the passed in values can be modified without affecting the table's output. -// -// New("foo", "bar").AddRow("fizz", "buzz").AddRow(time.Now()).AddRow(1, 2, 3).Print() -// // Output: -// // foo bar -// // fizz buzz -// // 2006-01-02 15:04:05.0 -0700 MST -// // 1 2 -// -// Print writes the string representation of the table to the provided writer. -// Print can be called multiple times, even after subsequent mutations of the -// provided data. The output is always preceded and followed by a new line. -type Table interface { - WithHeaderFormatter(f Formatter) Table - WithFirstColumnFormatter(f Formatter) Table - WithPadding(p int) Table - WithWriter(w io.Writer) Table - WithWidthFunc(f WidthFunc) Table - - AddRow(vals ...interface{}) Table - Print() -} - -// New creates a Table instance with the specified header(s) provided. The number -// of columns is fixed at this point to len(columnHeaders) and the defined defaults -// are set on the instance. -func New(columnHeaders ...interface{}) Table { - t := table{header: make([]string, len(columnHeaders))} - - t.WithPadding(DefaultPadding) - t.WithWriter(DefaultWriter) - t.WithHeaderFormatter(DefaultHeaderFormatter) - t.WithFirstColumnFormatter(DefaultFirstColumnFormatter) - t.WithWidthFunc(DefaultWidthFunc) - - for i, col := range columnHeaders { - t.header[i] = fmt.Sprint(col) - } - - return &t -} - -type table struct { - FirstColumnFormatter Formatter - HeaderFormatter Formatter - Padding int - Writer io.Writer - Width WidthFunc - - header []string - rows [][]string - widths []int -} - -func (t *table) WithHeaderFormatter(f Formatter) Table { - t.HeaderFormatter = f - return t -} - -func (t *table) WithFirstColumnFormatter(f Formatter) Table { - t.FirstColumnFormatter = f - return t -} - -func (t *table) WithPadding(p int) Table { - if p < 0 { - p = 0 - } - - t.Padding = p - return t -} - -func (t *table) WithWriter(w io.Writer) Table { - if w == nil { - w = os.Stdout - } - - t.Writer = w - return t -} - -func (t *table) WithWidthFunc(f WidthFunc) Table { - t.Width = f - return t -} - -func (t *table) AddRow(vals ...interface{}) Table { - row := make([]string, len(t.header)) - for i, val := range vals { - if i >= len(t.header) { - break - } - row[i] = fmt.Sprint(val) - } - t.rows = append(t.rows, row) - - return t -} - -func (t *table) Print() { - format := strings.Repeat("%s", len(t.header)) + "\n" - t.calculateWidths() - - t.printHeader(format) - for _, row := range t.rows { - t.printRow(format, row) - } -} - -func (t *table) printHeader(format string) { - vals := t.applyWidths(t.header, t.widths) - if t.HeaderFormatter != nil { - txt := t.HeaderFormatter(format, vals...) - fmt.Fprint(t.Writer, txt) - } else { - fmt.Fprintf(t.Writer, format, vals...) - } -} - -func (t *table) printRow(format string, row []string) { - vals := t.applyWidths(row, t.widths) - - if t.FirstColumnFormatter != nil { - vals[0] = t.FirstColumnFormatter("%s", vals[0]) - } - - fmt.Fprintf(t.Writer, format, vals...) -} - -func (t *table) calculateWidths() { - t.widths = make([]int, len(t.header)) - for _, row := range t.rows { - for i, v := range row { - if w := t.Width(v) + t.Padding; w > t.widths[i] { - t.widths[i] = w - } - } - } - - for i, v := range t.header { - if w := t.Width(v) + t.Padding; w > t.widths[i] { - t.widths[i] = w - } - } -} - -func (t *table) applyWidths(row []string, widths []int) []interface{} { - out := make([]interface{}, len(row)) - for i, s := range row { - out[i] = s + t.lenOffset(s, widths[i]) - } - return out -} - -func (t *table) lenOffset(s string, w int) string { - l := w - t.Width(s) - if l <= 0 { - return "" - } - return strings.Repeat(" ", l) -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/vendor/modules.txt new/vendor/modules.txt --- old/vendor/modules.txt 2024-08-12 07:46:42.000000000 +0200 +++ new/vendor/modules.txt 2024-09-14 16:23:28.000000000 +0200 @@ -53,7 +53,6 @@ github.com/prometheus/procfs/internal/util # github.com/rodaine/table v1.0.1 ## explicit; go 1.14 -github.com/rodaine/table # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2
