@@ -19,6 +19,7 @@ import (
1919 "asdf/internal/plugins"
2020 "asdf/internal/resolve"
2121 "asdf/internal/shims"
22+ "asdf/internal/toolversions"
2223 "asdf/internal/versions"
2324
2425 "github.com/urfave/cli/v2"
@@ -175,6 +176,15 @@ func Execute(version string) {
175176 return reshimCommand (logger , args .Get (0 ), args .Get (1 ))
176177 },
177178 },
179+ {
180+ Name : "where" ,
181+ Action : func (cCtx * cli.Context ) error {
182+ tool := cCtx .Args ().Get (0 )
183+ version := cCtx .Args ().Get (1 )
184+
185+ return whereCommand (logger , tool , version )
186+ },
187+ },
178188 {
179189 Name : "which" ,
180190 Action : func (cCtx * cli.Context ) error {
@@ -265,7 +275,7 @@ func getVersionInfo(conf config.Config, plugin plugins.Plugin, currentDir string
265275 installed := false
266276 if found {
267277 firstVersion := toolversion .Versions [0 ]
268- versionType , version := versions . ParseString (firstVersion )
278+ versionType , version := toolversions . Parse (firstVersion )
269279 installed = installs .IsInstalled (conf , plugin , versionType , version )
270280 }
271281 return toolversion , found , installed
@@ -663,8 +673,68 @@ func whichCommand(logger *log.Logger, command string) error {
663673 return nil
664674}
665675
676+ func whereCommand (logger * log.Logger , tool , version string ) error {
677+ conf , err := config .LoadConfig ()
678+ if err != nil {
679+ logger .Printf ("error loading config: %s" , err )
680+ return err
681+ }
682+
683+ currentDir , err := os .Getwd ()
684+ if err != nil {
685+ logger .Printf ("unable to get current directory: %s" , err )
686+ return err
687+ }
688+
689+ plugin := plugins .New (conf , tool )
690+ err = plugin .Exists ()
691+ if err != nil {
692+ if _ , ok := err .(plugins.PluginMissing ); ok {
693+ logger .Printf ("No such plugin: %s" , tool )
694+ }
695+ return err
696+ }
697+
698+ versionType , parsedVersion := toolversions .Parse (version )
699+
700+ if version == "" {
701+ // resolve version
702+ toolversions , found , err := resolve .Version (conf , plugin , currentDir )
703+ if err != nil {
704+ fmt .Printf ("err %#+v\n " , err )
705+ return err
706+ }
707+
708+ if found && len (toolversions .Versions ) > 0 && installs .IsInstalled (conf , plugin , "version" , toolversions .Versions [0 ]) {
709+ installPath := installs .InstallPath (conf , plugin , "version" , toolversions .Versions [0 ])
710+ logger .Printf ("%s" , installPath )
711+ return nil
712+ }
713+
714+ // not found
715+ msg := fmt .Sprintf ("No version is set for %s; please run `asdf <global | shell | local> %s <version>`" , tool , tool )
716+ logger .Print (msg )
717+ return errors .New (msg )
718+ }
719+
720+ if version == "system" {
721+ logger .Printf ("System version is selected" )
722+ return errors .New ("System version is selected" )
723+ }
724+
725+ if ! installs .IsInstalled (conf , plugin , versionType , parsedVersion ) {
726+ logger .Printf ("Version not installed" )
727+ return errors .New ("Version not installed" )
728+ }
729+
730+ installPath := installs .InstallPath (conf , plugin , versionType , parsedVersion )
731+ logger .Printf ("%s" , installPath )
732+
733+ return nil
734+ }
735+
666736func reshimToolVersion (conf config.Config , tool , version string , out io.Writer , errOut io.Writer ) error {
667- versionType , version := versions . ParseString (version )
737+ versionType , version := toolversions . Parse (version )
668738 return shims .GenerateForVersion (conf , plugins .New (conf , tool ), versionType , version , out , errOut )
669739}
670740
0 commit comments