File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,13 @@ import (
9
9
"github.com/sirupsen/logrus"
10
10
"github.com/spf13/cobra"
11
11
12
+ "github.com/lima-vm/lima/v2/cmd/yq"
12
13
"github.com/lima-vm/lima/v2/pkg/debugutil"
13
14
"github.com/lima-vm/lima/v2/pkg/version"
14
15
)
15
16
16
17
func main () {
18
+ yq .MaybeRunYQ ()
17
19
if err := newApp ().Execute (); err != nil {
18
20
logrus .Fatal (err )
19
21
}
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import (
17
17
"github.com/sirupsen/logrus"
18
18
"github.com/spf13/cobra"
19
19
20
+ "github.com/lima-vm/lima/v2/cmd/yq"
20
21
"github.com/lima-vm/lima/v2/pkg/debugutil"
21
22
"github.com/lima-vm/lima/v2/pkg/driver/external/server"
22
23
"github.com/lima-vm/lima/v2/pkg/fsutil"
@@ -32,6 +33,7 @@ const (
32
33
)
33
34
34
35
func main () {
36
+ yq .MaybeRunYQ ()
35
37
if runtime .GOOS == "windows" {
36
38
extras , hasExtra := os .LookupEnv ("_LIMA_WINDOWS_EXTRA_PATH" )
37
39
if hasExtra && strings .TrimSpace (extras ) != "" {
Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: Copyright The Lima Authors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // SPDX-FileCopyrightText: Copyright (c) 2017 Mike Farah
5
+
6
+ // This file has been adapted from https://github.com/mikefarah/yq/blob/v4.47.1/yq.go
7
+
8
+ package yq
9
+
10
+ import (
11
+ "os"
12
+ "path/filepath"
13
+ "strings"
14
+
15
+ command "github.com/mikefarah/yq/v4/cmd"
16
+ )
17
+
18
+ func main () {
19
+ cmd := command .New ()
20
+ args := os .Args [1 :]
21
+ _ , _ , err := cmd .Find (args )
22
+ if err != nil && args [0 ] != "__complete" {
23
+ // default command when nothing matches...
24
+ newArgs := []string {"eval" }
25
+ cmd .SetArgs (append (newArgs , os .Args [1 :]... ))
26
+ }
27
+ code := 0
28
+ if err := cmd .Execute (); err != nil {
29
+ code = 1
30
+ }
31
+ os .Exit (code )
32
+ }
33
+
34
+ // MaybeRunYQ runs as `yq` if the program name or first argument is `yq`.
35
+ // Only returns to caller if os.Args doesn't contain a `yq` command.
36
+ func MaybeRunYQ () {
37
+ progName := filepath .Base (os .Args [0 ])
38
+ // remove all extensions, so we match "yq.lima.exe"
39
+ progName , _ , _ = strings .Cut (progName , "." )
40
+ if progName == "yq" {
41
+ main ()
42
+ }
43
+ if len (os .Args ) > 1 && os .Args [1 ] == "yq" {
44
+ os .Args = os .Args [1 :]
45
+ main ()
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments