Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use --zls In any location #112

Merged
merged 7 commits into from
Jan 22, 2025
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 cli/meta/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
)

const (

VERSION = "v0.8.4"

// VERSION = "v0.0.0" // For testing zvm upgrade

)
Expand Down
1 change: 1 addition & 0 deletions cli/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (z *ZVM) setBin(ver string) error {
return err
}

log.Debug("Use", "version", ver)
return nil
}

Expand Down
19 changes: 11 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
module github.com/tristanisham/zvm


go 1.23


require (
github.com/charmbracelet/lipgloss v0.10.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/charmbracelet/log v0.4.0
github.com/schollz/progressbar/v3 v3.14.2
github.com/schollz/progressbar/v3 v3.18.0
github.com/tristanisham/clr v0.0.0-20221004001624-00ee60046d85
golang.org/x/mod v0.16.0
golang.org/x/sys v0.18.0
golang.org/x/mod v0.22.0
golang.org/x/sys v0.29.0
)

require (
github.com/charmbracelet/x/ansi v0.7.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
Expand All @@ -22,12 +25,12 @@ require (
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/urfave/cli/v2 v2.27.2
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/term v0.18.0 // indirect
github.com/urfave/cli/v3 v3.0.0-beta1
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/term v0.28.0 // indirect
)
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
github.com/charmbracelet/x/ansi v0.7.0 h1:/QfFmiXOGGwN6fRbzvQaYp7fu1pkxpZ3qFBZWBsP404=
github.com/charmbracelet/x/ansi v0.7.0/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -19,6 +23,8 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
Expand All @@ -35,26 +41,39 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.14.2 h1:EducH6uNLIWsr560zSV1KrTeUb/wZGAHqyMFIEa99ks=
github.com/schollz/progressbar/v3 v3.14.2/go.mod h1:aQAZQnhF4JGFtRJiw/eobaXpsqpVQAftEQ+hLGXaRc4=
github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA=
github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tristanisham/clr v0.0.0-20221004001624-00ee60046d85 h1:zD4b2hs7jZ2sJtgtNdpMZyo4D4/Ifct8SMxvPNNkHzs=
github.com/tristanisham/clr v0.0.0-20221004001624-00ee60046d85/go.mod h1:cKn2HV8Beq81OHjb2gja2ZiU4HAEQ6LSuxyaIT5Mg7o=
github.com/tristanisham/clr v0.0.0-20251004001624-00ee60046d85/go.mod h1:cKn2HV8Beq81OHjb2gja2ZiU4HAEQ6LSuxyaIT5Mg7o=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 h1:aAcj0Da7eBAtrTp03QXWvm88pSyOt+UgdZw2BFZ+lEw=
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg=
golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
93 changes: 49 additions & 44 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
package main

import (
"context"
"errors"
"fmt"
"os"
"strings"

"github.com/tristanisham/zvm/cli"
"github.com/tristanisham/zvm/cli/meta"
opts "github.com/urfave/cli/v2"
opts "github.com/urfave/cli/v3"

"github.com/charmbracelet/log"
)
Expand All @@ -22,25 +23,24 @@ var (
printUpgradeNotice bool = true
)

var zvmApp = &opts.App{
Name: "ZVM",
var zvmApp = &opts.Command{
Name: "zvm",
Usage: "Zig Version Manager",
Description: "zvm lets you easily install, upgrade, and switch between different versions of Zig.",
HelpName: "zvm",
Version: meta.VerCopy,
Copyright: "Copyright © 2025 Tristan Isham",
Suggest: true,
Before: func(ctx *opts.Context) error {
Before: func(ctx context.Context, cmd *opts.Command) (context.Context, error) {
zvm = *cli.Initialize()
return nil
return nil, nil
},
// app-global flags
Flags: []opts.Flag{
&opts.StringFlag{
Name: "color",
Usage: "enable (on, yes/y, enabled, true) or disable (off, no/n, disabled, false) colored ZVM output",
Value: "toggle",
Action: func(ctx *opts.Context, val string) error {
Action: func(ctx context.Context, cmd *opts.Command, val string) error {
switch val {
case "on", "yes", "enabled", "y", "true":
zvm.Settings.YesColor()
Expand Down Expand Up @@ -78,10 +78,10 @@ var zvmApp = &opts.App{
},
},
Description: "To install the latest version, use `master`",
Args: true,
ArgsUsage: " <ZIG VERSION>",
Action: func(ctx *opts.Context) error {
versionArg := strings.TrimPrefix(ctx.Args().First(), "v")
// Args: true,
ArgsUsage: " <ZIG VERSION>",
Action: func(ctx context.Context, cmd *opts.Command) error {
versionArg := strings.TrimPrefix(cmd.Args().First(), "v")

if versionArg == "" {
return errors.New("no version provided")
Expand All @@ -92,12 +92,12 @@ var zvmApp = &opts.App{

force := zvm.Settings.AlwaysForceInstall

if ctx.Bool("force") {
force = ctx.Bool("force")
if cmd.Bool("force") {
force = cmd.Bool("force")
}

zlsCompat := "only-runtime"
if ctx.Bool("full") {
if cmd.Bool("full") {
zlsCompat = "full"
}

Expand All @@ -108,7 +108,7 @@ var zvmApp = &opts.App{
}

// Install ZLS (if requested)
if ctx.Bool("zls") {
if cmd.Bool("zls") {
if err := zvm.InstallZls(req.Package, zlsCompat, force); err != nil {
return err
}
Expand All @@ -120,29 +120,34 @@ var zvmApp = &opts.App{
{
Name: "use",
Usage: "switch between versions of Zig",
Args: true,
// Args: true,
Flags: []opts.Flag{
&opts.BoolFlag{
Name: "sync",
Usage: "sync your current version of Zig with the repository",
},
},
Action: func(ctx *opts.Context) error {
if ctx.Bool("sync") {
Action: func(ctx context.Context, cmd *opts.Command) error {
if cmd.Bool("sync") {
return zvm.Sync()
} else {
versionArg := strings.TrimPrefix(ctx.Args().First(), "v")
return zvm.Use(versionArg)
versionArg := strings.TrimPrefix(cmd.Args().First(), "v")
if err := zvm.Use(versionArg); err != nil {
return err
}

fmt.Printf("Now using Zig %s\n", versionArg)
return nil
}
},
},
{
Name: "run",
Usage: "run a command with the given Zig version",
Args: true,
Action: func(ctx *opts.Context) error {
versionArg := strings.TrimPrefix(ctx.Args().First(), "v")
cmds := ctx.Args().Tail()
// Args: true,
Action: func(ctx context.Context, cmd *opts.Command) error {
versionArg := strings.TrimPrefix(cmd.Args().First(), "v")
cmds := cmd.Args().Tail()
return zvm.Run(versionArg, cmds)

},
Expand All @@ -151,7 +156,7 @@ var zvmApp = &opts.App{
Name: "list",
Usage: "list installed Zig versions. Flag `--all` to see remote options",
Aliases: []string{"ls"},
Args: true,
// Args: true,
Flags: []opts.Flag{
&opts.BoolFlag{
Name: "all",
Expand All @@ -163,11 +168,11 @@ var zvmApp = &opts.App{
Usage: "list set version maps",
},
},
Action: func(ctx *opts.Context) error {
Action: func(ctx context.Context, cmd *opts.Command) error {
log.Debug("Version Map", "url", zvm.Settings.VersionMapUrl, "cmd", "list/ls")
if ctx.Bool("all") {
if cmd.Bool("all") {
return zvm.ListRemoteAvailable()
} else if ctx.Bool("vmu") {
} else if cmd.Bool("vmu") {
if len(zvm.Settings.VersionMapUrl) == 0 {
if err := zvm.Settings.ResetVersionMap(); err != nil {
return err
Expand All @@ -194,40 +199,40 @@ var zvmApp = &opts.App{
Name: "uninstall",
Usage: "remove an installed version of Zig",
Aliases: []string{"rm"},
Args: true,
Action: func(ctx *opts.Context) error {
versionArg := strings.TrimPrefix(ctx.Args().First(), "v")
// Args: true,
Action: func(ctx context.Context, cmd *opts.Command) error {
versionArg := strings.TrimPrefix(cmd.Args().First(), "v")
return zvm.Uninstall(versionArg)
},
},
{
Name: "clean",
Usage: "remove build artifacts (good if you're a scrub)",
Action: func(ctx *opts.Context) error {
Action: func(ctx context.Context, cmd *opts.Command) error {
return zvm.Clean()
},
},
{
Name: "upgrade",
Usage: "self-upgrade ZVM",
Action: func(ctx *opts.Context) error {
Action: func(ctx context.Context, cmd *opts.Command) error {
printUpgradeNotice = false
return zvm.Upgrade()
},
},
{
Name: "vmu",
Usage: "set ZVM's version map URL for custom Zig distribution servers",
Args: true,
Subcommands: []*opts.Command{
// Args: true,
Commands: []*opts.Command{
{
Name: "zig",
Usage: "set ZVM's version map URL for custom Zig distribution servers",
Args: true,
Name: "zig",
Usage: "set ZVM's version map URL for custom Zig distribution servers",
// Args: true,
ArgsUsage: "",

Action: func(ctx *opts.Context) error {
url := ctx.Args().First()
Action: func(ctx context.Context, cmd *opts.Command) error {
url := cmd.Args().First()
log.Debug("user passed VMU", "url", url)

switch url {
Expand All @@ -253,9 +258,9 @@ var zvmApp = &opts.App{
{
Name: "zls",
Usage: "set ZVM's version map URL for custom ZLS Release Workers",
Args: true,
Action: func(ctx *opts.Context) error {
url := ctx.Args().First()
// Args: true,
Action: func(ctx context.Context, cmd *opts.Command) error {
url := cmd.Args().First()
log.Debug("user passed zrw", "url", url)

switch url {
Expand Down Expand Up @@ -301,7 +306,7 @@ func main() {
}

// run and report errors
if err := zvmApp.Run(os.Args); err != nil {
if err := zvmApp.Run(context.Background(), os.Args); err != nil {
// if meta.VERSION == "v0.7.9" && errors.Is(err, cli.ErrInvalidVersionMap) {
// meta.CtaGeneric("Help", `Encountered an issue while trying to install ZLS for Zig 'master'.

Expand Down