github.com/LGUG2Z/story@v0.4.1/cli/load.go (about)

     1  package cli
     2  
     3  import (
     4  	"github.com/LGUG2Z/story/git"
     5  	"github.com/LGUG2Z/story/manifest"
     6  	"github.com/spf13/afero"
     7  	"github.com/urfave/cli"
     8  )
     9  
    10  func LoadCmd(fs afero.Fs) cli.Command {
    11  	return cli.Command{
    12  		Name:  "load",
    13  		Usage: "Loads an existing story",
    14  		Action: func(c *cli.Context) error {
    15  			if isStory {
    16  				return ErrAlreadyWorkingOnAStory
    17  			}
    18  
    19  			if !c.Args().Present() {
    20  				return ErrCommandRequiresAnArgument
    21  			}
    22  
    23  			name := c.Args().First()
    24  			output, err := git.CheckoutBranch(git.CheckoutBranchOpts{Branch: name})
    25  			if err != nil {
    26  				return err
    27  			}
    28  
    29  			printGitOutput(output, metarepo)
    30  
    31  			story, err := manifest.LoadStory(fs)
    32  			if err != nil {
    33  				return err
    34  			}
    35  
    36  			for project := range story.Projects {
    37  				if err := ensureProjectIsCloned(fs, story, project); err != nil {
    38  					return err
    39  				}
    40  
    41  				output, err := git.CheckoutBranch(git.CheckoutBranchOpts{Branch: name, Project: project})
    42  				if err != nil {
    43  					return err
    44  				}
    45  
    46  				printGitOutput(output, project)
    47  			}
    48  
    49  			return nil
    50  		},
    51  	}
    52  }