34 lines
694 B
Go
Executable File
34 lines
694 B
Go
Executable File
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
type ListCommand struct {
|
|
GameDir string
|
|
}
|
|
|
|
func NewListCommand(gameDir string) *ListCommand {
|
|
return &ListCommand{GameDir: gameDir}
|
|
}
|
|
|
|
func (lc *ListCommand) Run() error {
|
|
versionsDir := path.Join(lc.GameDir, "versions")
|
|
if _, err := os.Stat(versionsDir); err != nil {
|
|
return fmt.Errorf("versions directory wasn't found inside %s", lc.GameDir)
|
|
}
|
|
entries, err := os.ReadDir(path.Join(lc.GameDir, "versions"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println("There are following versions installed:")
|
|
for _, entry := range entries {
|
|
if entry.IsDir() {
|
|
fmt.Println(entry.Name())
|
|
}
|
|
}
|
|
return nil
|
|
}
|