feat: better formatting for which/where printouts (#11)
* feat: better formatting for which/where printouts * chore: update version to 0.0.6
This commit is contained in:
parent
5bf3f36559
commit
d6bce67296
4 changed files with 45 additions and 13 deletions
3
cli.go
3
cli.go
|
@ -9,6 +9,7 @@ type Flags struct {
|
|||
AddPath bool
|
||||
NoCache bool
|
||||
Verbose bool
|
||||
RawOutput bool
|
||||
}
|
||||
|
||||
// Command definition for CLI subcommands.
|
||||
|
@ -99,6 +100,8 @@ func collectFlags(args []string) Flags {
|
|||
collected.NoCache = true
|
||||
case "--add-path":
|
||||
collected.AddPath = true
|
||||
case "--raw":
|
||||
collected.RawOutput = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
35
commands.go
35
commands.go
|
@ -21,7 +21,7 @@ var SHIMS = []string{
|
|||
const DEFAULT_PERMISSION = 0775
|
||||
|
||||
func writeShim(shimPath string) error {
|
||||
shimContent := []byte("#!/bin/bash\n$(v where) $@")
|
||||
shimContent := []byte("#!/bin/bash\n$(v where --raw) $@")
|
||||
if err := os.WriteFile(shimPath, shimContent, DEFAULT_PERMISSION); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -103,14 +103,23 @@ func ListVersions(args []string, flags Flags, currentState State) error {
|
|||
func Where(args []string, flags Flags, currentState State) error {
|
||||
selectedVersion, _ := DetermineSelectedPythonVersion(currentState)
|
||||
|
||||
var printedPath string
|
||||
if selectedVersion == "SYSTEM" {
|
||||
_, sysPath := DetermineSystemPython()
|
||||
fmt.Println(sysPath)
|
||||
return nil
|
||||
_, printedPath = DetermineSystemPython()
|
||||
} else {
|
||||
tag := VersionStringToStruct(selectedVersion)
|
||||
printedPath = GetStatePath("runtimes", fmt.Sprintf("py-%s", selectedVersion), "bin", fmt.Sprintf("python%s", tag.MajorMinor()))
|
||||
}
|
||||
|
||||
tag := VersionStringToStruct(selectedVersion)
|
||||
fmt.Println(GetStatePath("runtimes", fmt.Sprintf("py-%s", selectedVersion), "bin", fmt.Sprintf("python%s", tag.MajorMinor())))
|
||||
prefix := "Python path: "
|
||||
|
||||
if flags.RawOutput {
|
||||
prefix = ""
|
||||
} else {
|
||||
printedPath = Bold(printedPath)
|
||||
}
|
||||
|
||||
fmt.Printf("%s%s\n", prefix, printedPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -121,13 +130,21 @@ func Where(args []string, flags Flags, currentState State) error {
|
|||
// the system version is used and 'SYSTEM' is printed by Which.
|
||||
func Which(args []string, flags Flags, currentState State) error {
|
||||
selectedVersion, _ := DetermineSelectedPythonVersion(currentState)
|
||||
printedVersion := selectedVersion
|
||||
|
||||
if selectedVersion == "SYSTEM" {
|
||||
sysVersion, _ := DetermineSystemPython()
|
||||
fmt.Println(sysVersion)
|
||||
return nil
|
||||
printedVersion = fmt.Sprintf("%s (system)", sysVersion)
|
||||
}
|
||||
|
||||
fmt.Println(selectedVersion)
|
||||
prefix := "Python version: "
|
||||
|
||||
if flags.RawOutput {
|
||||
prefix = ""
|
||||
} else {
|
||||
printedVersion = Bold(printedVersion)
|
||||
}
|
||||
|
||||
fmt.Printf("%s%s\n", prefix, printedVersion)
|
||||
return nil
|
||||
}
|
||||
|
|
12
style.go
Normal file
12
style.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
RESET = "\033[0m"
|
||||
BOLD = "\033[1m"
|
||||
)
|
||||
|
||||
func Bold(text string) string {
|
||||
return fmt.Sprintf("%s%s%s", BOLD, text, RESET)
|
||||
}
|
2
v.go
2
v.go
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
Version = "0.0.5"
|
||||
Version = "0.0.6"
|
||||
Author = "Marc Cataford <hello@karnov.club>"
|
||||
Homepage = "https://github.com/mcataford/v"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue