Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
status: add project status
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Nov 10, 2017
1 parent c47c866 commit 63a5275
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
return err
}

if len(args) > 0 {
return runProjectStatus(ctx, args, p, sm)
}

var buf bytes.Buffer
var out outputter
switch {
Expand Down Expand Up @@ -643,3 +647,78 @@ func collectConstraints(ptree pkgtree.PackageTree, p *dep.Project, sm gps.Source
// TODO
return map[string][]gps.Constraint{}
}

type projectStatus struct {
Project string
Version string
Constraints []string
Source string
AltSource string
PubVersions []string
Revision string
LatestAllowed string
SourceType string
Packages string
ProjectImporters map[string]string
PackageImporters map[string]string
UpstreamExists bool
UpstreamVersionExists bool
}

func (ps projectStatus) String() string {
return fmt.Sprintf(`
PROJECT: %s
VERSION: %s
CONSTRAINTS: %s
SOURCE: %s
ALT SOURCE: %s
PUB VERSION: %s
REVISION: %s
LATEST ALLOWED: %s
SOURCE TYPE: %s
PACKAGES: %s
PROJECT IMPORTERS: %s
PACKAGE IMPORTERS: %s
UPSTREAM EXISTS: %t
UPSTREAM VERSION EXISTS: %t
`,
ps.Project, ps.Version, ps.Constraints, ps.Source, ps.AltSource,
ps.PubVersions, ps.Revision, ps.LatestAllowed, ps.SourceType, ps.Packages,
ps.ProjectImporters, ps.PackageImporters, ps.UpstreamExists,
ps.UpstreamVersionExists)
}

func runProjectStatus(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager) error {
// Collect all the project roots from the arguments.
var prs []gps.ProjectRoot

for _, arg := range args {
pr, err := sm.DeduceProjectRoot(arg)
if err != nil {
return err
}
prs = append(prs, pr)
}

for _, pr := range prs {
// Create projectStatus and add Project name.
projStatus := projectStatus{
Project: string(pr),
}

// Get the currently selected version from from lock.
for _, pl := range p.Lock.Projects() {
if pr == pl.Ident().ProjectRoot {
projStatus.Version = pl.Version().String()
projStatus.Source = projStatus.Project
projStatus.AltSource = pl.Ident().Source
rev, _, _ := gps.VersionComponentStrings(pl.Version())
projStatus.Revision = rev
}
}

fmt.Println(projStatus)
}

return nil
}

0 comments on commit 63a5275

Please sign in to comment.