-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple flags together (#9)
* feat: support multiple flags together * fix: pr template
- Loading branch information
1 parent
c446b52
commit 10ac1c3
Showing
8 changed files
with
230 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"runtime" | ||
|
||
"github.com/VassilisPallas/gvs/logger" | ||
"github.com/VassilisPallas/gvs/version" | ||
) | ||
|
||
type CLI struct { | ||
versions []*version.ExtendedVersion | ||
versioner version.Versioner | ||
log logger.Logger | ||
} | ||
|
||
func (cli CLI) Install(selectedVersion *version.ExtendedVersion) error { | ||
cli.log.Info("selected %s version\n", selectedVersion.Version) | ||
return cli.versioner.Install(selectedVersion, runtime.GOOS, runtime.GOARCH) | ||
} | ||
|
||
func (cli CLI) InstallVersion(goVersion string) error { | ||
semver := &version.Semver{} | ||
err := version.ParseSemver(goVersion, semver) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
selectedVersion := cli.versioner.FindVersionBasedOnSemverName(cli.versions, semver) | ||
if selectedVersion != nil { | ||
return fmt.Errorf("%s is not a valid version", semver.GetVersion()) | ||
} | ||
|
||
return cli.Install(selectedVersion) | ||
} | ||
|
||
func (cli CLI) InstallLatestVersion() error { | ||
selectedIndex := cli.versioner.GetLatestVersion(cli.versions) | ||
if selectedIndex == -1 { | ||
return errors.New("latest version not found") | ||
} | ||
|
||
selectedVersion := cli.versions[selectedIndex] | ||
|
||
return cli.Install(selectedVersion) | ||
} | ||
|
||
func (cli CLI) DeleteUnusedVersions() error { | ||
deleted_count, err := cli.versioner.DeleteUnusedVersions(cli.versions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if deleted_count > 0 { | ||
cli.log.PrintMessage("All the unused version are deleted!") | ||
} else { | ||
cli.log.PrintMessage("Nothing to delete") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func New(versions []*version.ExtendedVersion, versioner version.Versioner, log logger.Logger) CLI { | ||
return CLI{versions: versions, versioner: versioner, log: log} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.