Skip to content

Commit

Permalink
bugfix for command 'use', add new command 'vmr installed-sdks'
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Nov 12, 2024
1 parent 8314f22 commit 8a3e531
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/vmr/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *Cli) initiate() {
c.rootCmd.AddCommand(vcli.ShowSDKCmd)
c.rootCmd.AddCommand(vcli.SearchVersionsCmd)
c.rootCmd.AddCommand(vcli.ShowInstalledCmd)
c.rootCmd.AddCommand(vcli.ShowInstalledSDKs)
c.rootCmd.AddCommand(vcli.UninstallVersionCmd)
}

Expand Down
1 change: 1 addition & 0 deletions cmd/vmr/cli/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var useCmd = &cobra.Command{
if ok, _ := cmd.Flags().GetBool("enable-locked-version"); ok {
l := installer.NewVLocker()
l.HookForCdCommand()
return
}

if len(args) == 0 {
Expand Down
12 changes: 12 additions & 0 deletions cmd/vmr/cli/vcli/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ var ShowInstalledCmd = &cobra.Command{
l.Show()
},
}

var ShowInstalledSDKs = &cobra.Command{
Use: "installed-sdks",
Aliases: []string{"in"},
GroupID: GroupID,
Short: "Shows installed SDKs.",
Long: "Example: vmr in.",
Run: func(cmd *cobra.Command, args []string) {
l := cliui.NewSDKSearcher()
l.PrintInstalledSDKs()
},
}
20 changes: 20 additions & 0 deletions internal/tui/cliui/sdk_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ func (v *SDKSearcher) ShowInstalledOnly() (nextEvent, selectedItem string) {
return
}

func (v *SDKSearcher) PrintInstalledSDKs() {
v.SdkList = download.GetSDKList()
rows := download.GetSDKSortedRows(v.SdkList)

installedRows := []table.Row{}
for _, r := range rows {
if install.IsSDKInstalledByVMR(r[0]) {
installedRows = append(installedRows, r)
}
}
if len(installedRows) == 0 {
gprint.PrintWarning("no installed sdk found!")
return
}

for _, r := range installedRows {
gprint.PrintInfo(r[0])
}
}

func (v *SDKSearcher) RegisterKeyEvents(ll *table.List) {
// Open homepage.
ll.SetKeyEventForTable("o", table.KeyEvent{
Expand Down

0 comments on commit 8a3e531

Please sign in to comment.