2023-11-05 01:28:11 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2024-01-23 17:55:06 +00:00
|
|
|
cli "v/cli"
|
2024-01-26 04:20:26 +00:00
|
|
|
python "v/python"
|
2024-01-23 17:45:08 +00:00
|
|
|
state "v/state"
|
2023-11-05 01:28:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-11-29 01:24:00 +00:00
|
|
|
Version = "0.0.8"
|
2023-11-05 01:58:31 +00:00
|
|
|
Author = "Marc Cataford <hello@karnov.club>"
|
|
|
|
Homepage = "https://github.com/mcataford/v"
|
2023-11-05 01:28:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Main entrypoint.
|
|
|
|
func main() {
|
|
|
|
args := os.Args[1:]
|
2024-01-23 17:45:08 +00:00
|
|
|
currentState := state.ReadState()
|
2023-11-05 01:28:11 +00:00
|
|
|
|
2024-01-26 05:27:46 +00:00
|
|
|
root := cli.Namespace{Label: ""}
|
|
|
|
root.AddCommand(
|
|
|
|
"init", Initialize, "v init", "Initializes the v state.",
|
|
|
|
)
|
2023-11-05 01:28:11 +00:00
|
|
|
|
2024-01-26 05:27:46 +00:00
|
|
|
pythonCommands := cli.Namespace{Label: "python"}
|
|
|
|
pythonCommands.AddCommand(
|
|
|
|
"install", python.InstallPython, "v python install <version>", "Downloads, builds and installs a new version of Python.",
|
2023-11-05 01:28:11 +00:00
|
|
|
).AddCommand(
|
2024-01-26 05:27:46 +00:00
|
|
|
"uninstall", python.UninstallPython, "v python uninstall <version>", "Uninstalls the given Python version.",
|
2023-11-05 01:28:11 +00:00
|
|
|
).AddCommand(
|
2024-01-26 05:27:46 +00:00
|
|
|
"use", python.Use, "v python use <version>", "Selects which Python version to use.",
|
2023-11-05 01:28:11 +00:00
|
|
|
).AddCommand(
|
2024-01-26 05:27:46 +00:00
|
|
|
"ls", python.ListVersions, "v python ls", "Lists the installed Python versions.",
|
2023-11-05 01:28:11 +00:00
|
|
|
).AddCommand(
|
2024-01-26 05:27:46 +00:00
|
|
|
"version", python.CurrentVersion, "v python version", "Prints the current version and its source.",
|
2023-11-05 01:28:11 +00:00
|
|
|
).AddCommand(
|
2024-01-26 05:27:46 +00:00
|
|
|
"which", python.Which, "v python which", "Prints the path to the current Python version.",
|
|
|
|
)
|
|
|
|
|
|
|
|
cli := cli.CLI{
|
|
|
|
Metadata: map[string]string{
|
|
|
|
"Version": Version,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.AddNamespace(root).AddNamespace(pythonCommands)
|
|
|
|
|
|
|
|
err := cli.Run(args, currentState)
|
2023-11-05 01:28:11 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|