Skip to content

Commit

Permalink
Merge pull request #129 from gkiki90/step_info
Browse files Browse the repository at this point in the history
step_info
  • Loading branch information
viktorbenei committed Sep 3, 2015
2 parents 3f68e2a + be9c102 commit e722bdb
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
11 changes: 11 additions & 0 deletions cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ var (
flCollection,
},
},
{
Name: "step-info",
Aliases: []string{"i"},
Usage: "Provides information (step ID, last version, given version) about specified step.",
Action: stepInfo,
Flags: []cli.Flag{
flCollection,
flID,
flVersion,
},
},
{
Name: "download",
Aliases: []string{"d"},
Expand Down
2 changes: 0 additions & 2 deletions cli/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
)

func download(c *cli.Context) {
log.Info("[STEPMAN] - Download")

// Input validation
collectionURI := c.String(CollectionKey)
if collectionURI == "" {
Expand Down
83 changes: 83 additions & 0 deletions cli/step_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package cli

import (
"encoding/json"
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/bitrise-io/stepman/stepman"
"github.com/codegangsta/cli"
)

// StepInfoModel ...
type StepInfoModel struct {
StepID string `json:"step_id,omitempty" yaml:"step_id,omitempty"`
StepVersion string `json:"step_version,omitempty" yaml:"step_version,omitempty"`
LatestVersion string `json:"latest_version,omitempty" yaml:"latest_version,omitempty"`
}

func getStepInfoString(id, version, latest string) (string, error) {
stepInfo := StepInfoModel{
StepID: id,
StepVersion: version,
LatestVersion: latest,
}

bytes, err := json.Marshal(stepInfo)
if err != nil {
return "", err
}
return string(bytes), nil
}

func stepInfo(c *cli.Context) {
// Input validation
collectionURI := c.String(CollectionKey)
if collectionURI == "" {
log.Fatalln("[STEPMAN] - No step collection specified")
}

id := c.String(IDKey)
if id == "" {
log.Fatal("[STEPMAN] - Missing step id")
}

version := c.String(VersionKey)

// Check if step exist in collection
collection, err := stepman.ReadStepSpec(collectionURI)
if err != nil {
log.Fatalln("[STEPMAN] - Failed to read steps spec (spec.json)")
}

stepFound := false
if version == "" {
stepFound = collection.IsStepExist(id)
} else {
_, stepFound = collection.GetStep(id, version)
}

if !stepFound {
if version == "" {
log.Fatalf("[STEPMAN] - Collection doesn't contain any version of step (id:%s)", id)
} else {
log.Fatalf("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s)", id, version)
}
}

latest, err := collection.GetLatestStepVersion(id)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get latest version of step (id:%s)", id)
}

if version == "" {
version = latest
}

stepInfoString, err := getStepInfoString(id, version, latest)
if err != nil {
log.Fatal("Failed to generate step info, err:", err)
}

fmt.Println(stepInfoString)
}

0 comments on commit e722bdb

Please sign in to comment.