Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lesiw committed Sep 29, 2024
1 parent 8819ed0 commit f2ef176
Show file tree
Hide file tree
Showing 38 changed files with 1,074 additions and 822 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: main
on: [push]
jobs:
op:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: '"$(wget -O- lesiw.io/op | sh)"'
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
linters:
enable:
- errname
- errcheck
- gocheckcompilerdirectives
- gocyclo
- lll
- makezero
- godot
- unparam
- unused

linters-settings:
gocyclo:
min-complexity: 15
lll:
tab-width: 4
line-length: 79
1 change: 1 addition & 0 deletions .ops/.uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add445f6-5937-4cde-af0a-e898da9db005
15 changes: 15 additions & 0 deletions .ops/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module ops.localhost

go 1.23.1

require (
labs.lesiw.io/ops v0.0.0-20240924235308-80435cd25815
lesiw.io/ops v0.9.0
)

require (
golang.org/x/sync v0.7.0 // indirect
lesiw.io/clerk v0.1.0 // indirect
lesiw.io/cmdio v0.0.0-20240723224912-c34a917524ae // indirect
lesiw.io/flag v0.7.0 // indirect
)
16 changes: 16 additions & 0 deletions .ops/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
labs.lesiw.io/ops v0.0.0-20240924235308-80435cd25815 h1:zRGYAjG5IQMcBYHZ9d9Ev2H5GCBNQ5iWZBNBZyqrFQE=
labs.lesiw.io/ops v0.0.0-20240924235308-80435cd25815/go.mod h1:ObOCJfTxz4pLbeeps37n0bEfzkbPlalhNppV0uhZ/ak=
lesiw.io/clerk v0.1.0 h1:hamIinfP4nfr6cxqV9z8ZdQqRif9IlprC9mjRPkG3Dk=
lesiw.io/clerk v0.1.0/go.mod h1:WMyvgTe+3Eob36b6KX86MOaxaeNMvv/HZTSsf2Dedhg=
lesiw.io/cmdio v0.0.0-20240723224912-c34a917524ae h1:aqHZcLDlBAa0oDoE+t2K7tGDBtHKB60eEou/Z76vtKg=
lesiw.io/cmdio v0.0.0-20240723224912-c34a917524ae/go.mod h1:1QvHpQzUItUIaITiA5aQAdZEvaNXn5c98EOaRxVsfXs=
lesiw.io/flag v0.7.0 h1:+8rTdoplDMBhOSKok5eKP6ZuLLPTodkDABRY7jfX5JU=
lesiw.io/flag v0.7.0/go.mod h1:bJx6Hir8MAXkNiO6BbrvhwZuaJF4rQWthQ7pc1DlWZY=
lesiw.io/ops v0.9.0 h1:39Y7rNC2KXB+AS7Hi6xSf45iiqjnM2Ou6YmXxjndQHA=
lesiw.io/ops v0.9.0/go.mod h1:13u2irogMVNWiZqfom1d4FGPnK4c1iCQ53QvwsRIJbE=
17 changes: 17 additions & 0 deletions .ops/ops.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"os"

"labs.lesiw.io/ops/golib"
"lesiw.io/ops"
)

type Ops struct{ golib.Ops }

func main() {
if len(os.Args) < 2 {
os.Args = append(os.Args, "check")
}
ops.Handle(Ops{})
}
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

[![Go Reference](https://pkg.go.dev/badge/lesiw.io/cmdio.svg)](https://pkg.go.dev/lesiw.io/cmdio)

``` go
// Package cmdio provides an interface to treat commands as an I/O stream.
```
Package cmdio provides portable interfaces for commands and command runners.
99 changes: 0 additions & 99 deletions box.go

This file was deleted.

2 changes: 2 additions & 0 deletions clerk.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.github/workflows/main.yml 62efcdd9a8f00f489693e4f0f916429822dc311f
.golangci.yml 179a5718940f1682437550116dc75276b12d950e
30 changes: 25 additions & 5 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"golang.org/x/sync/errgroup"
)

// Copy copies the output of each stream into the input of the next stream.
// When output is finished copying from one stream, the receiving stream is
// closed if it is an [io.Closer].
func Copy(
dst io.Writer, src io.Reader, mid ...io.ReadWriter,
) (written int64, err error) {
Expand All @@ -18,6 +21,7 @@ func Copy(
total = make(chan int64)
)
go func() {
var written int64
for n := range count {
written += n
}
Expand All @@ -34,6 +38,7 @@ func Copy(
} else {
w = mid[i+1]
}
i := i
w := w
r := r
g.Go(func() (err error) {
Expand All @@ -46,16 +51,31 @@ func Copy(
}
}()
if n, err := io.Copy(w, r); err != nil {
return err
return copyError{err, i + 1}
} else {
count <- n
}
return nil
})
}
if err := g.Wait(); err != nil {
return 0, err
}
err = g.Wait()
close(count)
return <-total, nil
return <-total, err
}

type copyError struct {
err error
off int
}

func (e copyError) Error() string {
return e.err.Error()
}

func (e copyError) Unwrap() error {
return e.err
}

func (e copyError) Offset() int {
return e.off
}
31 changes: 31 additions & 0 deletions copy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmdio_test

import (
"io"
"log"

"lesiw.io/cmdio"
"lesiw.io/cmdio/sys"
)

// nolint: errcheck
func ExampleCopy() {
rnr := sys.Runner()

defer rnr.Run("rm", "-f", "/tmp/cmdio_test.txt")
_, err := cmdio.Copy(
io.Discard,
rnr.Command("echo", "hello world"),
rnr.Command("tee", "/tmp/cmdio_test.txt"),
)
if err != nil {
log.Fatal(err)
}

err = rnr.Run("cat", "/tmp/cmdio_test.txt")
if err != nil {
log.Fatal(err)
}
// Output:
// hello world
}
17 changes: 0 additions & 17 deletions env_test.go

This file was deleted.

56 changes: 0 additions & 56 deletions error.go

This file was deleted.

Loading

0 comments on commit f2ef176

Please sign in to comment.