Skip to content

Commit

Permalink
support start playground offline when specify version (pingcap#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar committed Sep 17, 2021
1 parent d2405b3 commit 726aac2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
14 changes: 10 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ func (lr *listResult) print() {
}

func showComponentList(env *environment.Environment, opt listOptions) (*listResult, error) {
err := env.V1Repository().UpdateComponentManifests()
if err != nil {
tui.ColorWarningMsg.Fprint(os.Stderr, "Warn: Update component manifest failed, err_msg=[", err.Error(), "]\n")
if !opt.installedOnly {
err := env.V1Repository().UpdateComponentManifests()
if err != nil {
tui.ColorWarningMsg.Fprint(os.Stderr, "Warn: Update component manifest failed, err_msg=[", err.Error(), "]\n")
}
}

installed, err := env.Profile().InstalledComponents()
Expand Down Expand Up @@ -183,7 +185,11 @@ func showComponentList(env *environment.Environment, opt listOptions) (*listResu
func showComponentVersions(env *environment.Environment, component string, opt listOptions) (*listResult, error) {
var comp *v1manifest.Component
var err error
comp, err = env.V1Repository().FetchComponentManifest(component, false)
if opt.installedOnly {
comp, err = env.V1Repository().LocalComponentManifest(component, false)
} else {
comp, err = env.V1Repository().FetchComponentManifest(component, false)
}
if err != nil {
return nil, errors.Annotate(err, "failed to fetch component")
}
Expand Down
41 changes: 19 additions & 22 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,23 @@ func (r *V1Repository) FetchComponentManifest(id string, withYanked bool) (com *
return r.updateComponentManifest(id, withYanked)
}

// LocalComponentManifest load the component manifest from local.
func (r *V1Repository) LocalComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error) {
index := v1manifest.Index{}
_, exists, err := r.Local().LoadManifest(&index)
if err != nil {
return nil, err
}
if !exists {
return r.FetchComponentManifest(id, withYanked)
}

components := index.ComponentList()
comp := components[id]
filename := v1manifest.ComponentManifestFilename(id)
return r.Local().LoadComponentManifest(&comp, filename)
}

// ComponentVersion returns version item of a component
func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) {
manifest, err := r.FetchComponentManifest(id, includeYanked)
Expand Down Expand Up @@ -758,27 +775,7 @@ func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1

// LocalComponentVersion returns version item of a component from local manifest file
func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error) {
index := v1manifest.Index{}
_, exists, err := r.Local().LoadManifest(&index)
if err != nil {
return nil, err
}
if !exists {
err = r.ensureManifests()
if err != nil {
return nil, err
}
_, _, err := r.Local().LoadManifest(&index)

if err != nil {
return nil, err
}
}

components := index.ComponentList()
comp := components[id]
filename := v1manifest.ComponentManifestFilename(id)
manifest, err := r.Local().LoadComponentManifest(&comp, filename)
manifest, err := r.LocalComponentManifest(id, includeYanked)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -806,7 +803,7 @@ func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool)

// ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) {
manifest, err := r.FetchComponentManifest(id, false)
manifest, err := r.LocalComponentManifest(id, false)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 726aac2

Please sign in to comment.