Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/lima-guestagent/main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/cmd/yq"
"github.com/lima-vm/lima/v2/pkg/debugutil"
"github.com/lima-vm/lima/v2/pkg/version"
)

func main() {
yq.MaybeRunYQ()
if err := newApp().Execute(); err != nil {
logrus.Fatal(err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/cmd/yq"
"github.com/lima-vm/lima/v2/pkg/debugutil"
"github.com/lima-vm/lima/v2/pkg/driver/external/server"
"github.com/lima-vm/lima/v2/pkg/fsutil"
Expand All @@ -32,6 +33,7 @@ const (
)

func main() {
yq.MaybeRunYQ()
if runtime.GOOS == "windows" {
extras, hasExtra := os.LookupEnv("_LIMA_WINDOWS_EXTRA_PATH")
if hasExtra && strings.TrimSpace(extras) != "" {
Expand Down
47 changes: 47 additions & 0 deletions cmd/yq/yq.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: Copyright The Lima Authors
// SPDX-License-Identifier: Apache-2.0

// SPDX-FileCopyrightText: Copyright (c) 2017 Mike Farah

// This file has been adapted from https://github.com/mikefarah/yq/blob/v4.47.1/yq.go

package yq

import (
"os"
"path/filepath"
"strings"

command "github.com/mikefarah/yq/v4/cmd"
)

func main() {
cmd := command.New()
args := os.Args[1:]
_, _, err := cmd.Find(args)
if err != nil && args[0] != "__complete" {
// default command when nothing matches...
newArgs := []string{"eval"}
cmd.SetArgs(append(newArgs, os.Args[1:]...))
}
code := 0
if err := cmd.Execute(); err != nil {
code = 1
}
os.Exit(code)
}

// MaybeRunYQ runs as `yq` if the program name or first argument is `yq`.
// Only returns to caller if os.Args doesn't contain a `yq` command.
func MaybeRunYQ() {
progName := filepath.Base(os.Args[0])
// remove all extensions, so we match "yq.lima.exe"
progName, _, _ = strings.Cut(progName, ".")
if progName == "yq" {
main()
}
if len(os.Args) > 1 && os.Args[1] == "yq" {
os.Args = os.Args[1:]
main()
}
}
Loading