Skip to content

Commit 34e4f10

Browse files
committed
feat: tap
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent f64f99e commit 34e4f10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+11696
-0
lines changed

cmd/command_posix.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//go:build !windows
2+
3+
package cmd
4+
5+
import (
6+
"context"
7+
"os"
8+
"os/exec"
9+
"syscall"
10+
)
11+
12+
func newCommandContext(ctx context.Context, cmd string, args []string) *exec.Cmd {
13+
ce := exec.CommandContext(ctx, cmd, args...)
14+
ce.SysProcAttr = &syscall.SysProcAttr{
15+
Setpgid: true,
16+
}
17+
ce.Stdin, ce.Stdout, ce.Stderr = os.Stdin, os.Stdout, os.Stderr
18+
19+
return ce
20+
}

cmd/command_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
func newCommandContext(ctx context.Context, cmd string, args []string) *exec.Cmd {
10+
ce := exec.CommandContext(ctx, cmd, args...)
11+
ce.Stdin, ce.Stdout, ce.Stderr = os.Stdin, os.Stdout, os.Stderr
12+
13+
return ce
14+
}

cmd/delegate.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
"os"
9+
10+
"github.com/seal-io/tap/pkg/workingdir"
11+
"github.com/seal-io/tap/utils/set"
12+
"github.com/seal-io/tap/utils/version"
13+
14+
_ "github.com/seal-io/tap/utils/logging"
15+
)
16+
17+
func Delegate(ctx context.Context, cmd string, args []string) (err error) {
18+
// Setup working dir.
19+
args, err = workingdir.Setup(args)
20+
if err != nil {
21+
return fmt.Errorf("error setting up the working directory: %w", err)
22+
}
23+
24+
// Delegate.
25+
return delegate(ctx, cmd, args)
26+
}
27+
28+
func delegate(ctx context.Context, cmd string, args []string) error {
29+
// Construct execution.
30+
ce := newCommandContext(ctx, cmd, args)
31+
32+
// Hijack version command.
33+
as := set.New(args...)
34+
if as.HasAny("version", "-v", "-version", "--version") {
35+
if !as.Has("-json") {
36+
fmt.Printf("Tap %s\n", version.Get())
37+
} else {
38+
// Merge the version information into the JSON output.
39+
var buf bytes.Buffer
40+
ce.Stdout = &buf
41+
ce.Stderr = &buf
42+
43+
if err := ce.Run(); err == nil {
44+
var ot map[string]any
45+
_ = json.Unmarshal(buf.Bytes(), &ot)
46+
ot["tap_version"] = version.Version
47+
ot["tap_git_commit"] = version.GitCommit
48+
bs, _ := json.MarshalIndent(ot, "", " ")
49+
_, _ = fmt.Fprintf(os.Stdout, "%s\n", string(bs))
50+
51+
return nil
52+
}
53+
}
54+
}
55+
56+
return ce.Run()
57+
}

go.mod

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,94 @@
11
module github.com/seal-io/tap
22

33
go 1.21
4+
5+
replace (
6+
github.com/hashicorp/hcl/v2 => ./staging/hcl
7+
github.com/hashicorp/terraform => ./staging/terraform
8+
github.com/seal-io/tap/utils => ./staging/utils
9+
)
10+
11+
require (
12+
github.com/hashicorp/go-version v1.6.0
13+
github.com/hashicorp/hcl/v2 v2.19.1
14+
github.com/hashicorp/terraform v1.6.6
15+
github.com/seal-io/tap/utils v0.0.0-00010101000000-000000000000
16+
github.com/spf13/afero v1.11.0
17+
github.com/stretchr/testify v1.8.4
18+
github.com/zclconf/go-cty v1.14.1
19+
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
20+
)
21+
22+
require (
23+
cloud.google.com/go v0.111.0 // indirect
24+
cloud.google.com/go/compute v1.23.3 // indirect
25+
cloud.google.com/go/compute/metadata v0.2.3 // indirect
26+
cloud.google.com/go/iam v1.1.5 // indirect
27+
cloud.google.com/go/storage v1.36.0 // indirect
28+
github.com/agext/levenshtein v1.2.3 // indirect
29+
github.com/apparentlymart/go-cidr v1.1.0 // indirect
30+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
31+
github.com/apparentlymart/go-versions v1.0.2 // indirect
32+
github.com/aws/aws-sdk-go v1.49.13 // indirect
33+
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
34+
github.com/bmatcuk/doublestar v1.3.4 // indirect
35+
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d // indirect
36+
github.com/coreos/pkg v0.0.0-20230601102743-20bbbf26f4d8 // indirect
37+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
38+
github.com/fatih/color v1.16.0 // indirect
39+
github.com/felixge/httpsnoop v1.0.4 // indirect
40+
github.com/go-logr/logr v1.3.0 // indirect
41+
github.com/go-logr/stdr v1.2.2 // indirect
42+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
43+
github.com/golang/protobuf v1.5.3 // indirect
44+
github.com/google/go-cmp v0.6.0 // indirect
45+
github.com/google/s2a-go v0.1.7 // indirect
46+
github.com/google/uuid v1.5.0 // indirect
47+
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
48+
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
49+
github.com/hashicorp/errwrap v1.1.0 // indirect
50+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
51+
github.com/hashicorp/go-getter v1.7.3 // indirect
52+
github.com/hashicorp/go-hclog v1.6.2 // indirect
53+
github.com/hashicorp/go-multierror v1.1.1 // indirect
54+
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
55+
github.com/hashicorp/go-safetemp v1.0.0 // indirect
56+
github.com/hashicorp/go-uuid v1.0.3 // indirect
57+
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
58+
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
59+
github.com/jmespath/go-jmespath v0.4.0 // indirect
60+
github.com/klauspost/compress v1.15.11 // indirect
61+
github.com/kr/pretty v0.3.1 // indirect
62+
github.com/mattn/go-colorable v0.1.13 // indirect
63+
github.com/mattn/go-isatty v0.0.20 // indirect
64+
github.com/mitchellh/go-homedir v1.1.0 // indirect
65+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
66+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
67+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
68+
github.com/rogpeppe/go-internal v1.10.0 // indirect
69+
github.com/ulikunitz/xz v0.5.11 // indirect
70+
github.com/zclconf/go-cty-yaml v1.0.3 // indirect
71+
go.opencensus.io v0.24.0 // indirect
72+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
73+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
74+
go.opentelemetry.io/otel v1.21.0 // indirect
75+
go.opentelemetry.io/otel/metric v1.21.0 // indirect
76+
go.opentelemetry.io/otel/trace v1.21.0 // indirect
77+
golang.org/x/crypto v0.17.0 // indirect
78+
golang.org/x/mod v0.14.0 // indirect
79+
golang.org/x/net v0.19.0 // indirect
80+
golang.org/x/oauth2 v0.15.0 // indirect
81+
golang.org/x/sync v0.5.0 // indirect
82+
golang.org/x/sys v0.16.0 // indirect
83+
golang.org/x/text v0.14.0 // indirect
84+
golang.org/x/time v0.5.0 // indirect
85+
google.golang.org/api v0.154.0 // indirect
86+
google.golang.org/appengine v1.6.8 // indirect
87+
google.golang.org/genproto v0.0.0-20231212172506-995d672761c0 // indirect
88+
google.golang.org/genproto/googleapis/api v0.0.0-20231211222908-989df2bf70f3 // indirect
89+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231211222908-989df2bf70f3 // indirect
90+
google.golang.org/grpc v1.60.1 // indirect
91+
google.golang.org/protobuf v1.32.0 // indirect
92+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
93+
gopkg.in/yaml.v3 v3.0.1 // indirect
94+
)

0 commit comments

Comments
 (0)