github.com/simonferquel/app@v0.6.1-0.20181012141724-68b7cccf26ac/cmd/docker-app/split.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/docker/app/internal/packager"
     5  	"github.com/docker/cli/cli"
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  var splitOutputDir string
    10  
    11  func splitCmd() *cobra.Command {
    12  	cmd := &cobra.Command{
    13  		Use:   "split [<app-name>] [-o output]",
    14  		Short: "Split a single-file application into multiple files",
    15  		Args:  cli.RequiresMaxArgs(1),
    16  		RunE: func(cmd *cobra.Command, args []string) error {
    17  			extractedApp, err := packager.Extract(firstOrEmpty(args))
    18  			if err != nil {
    19  				return err
    20  			}
    21  			defer extractedApp.Cleanup()
    22  			inPlace := false
    23  			if splitOutputDir == "" {
    24  				splitOutputDir, inPlace = handleInPlace(extractedApp)
    25  			}
    26  			if err := packager.Split(extractedApp, splitOutputDir); err != nil {
    27  				return err
    28  			}
    29  			if inPlace {
    30  				return removeAndRename(splitOutputDir, extractedApp.Path)
    31  			}
    32  			return nil
    33  		},
    34  	}
    35  	cmd.Flags().StringVarP(&splitOutputDir, "output", "o", "", "Output application directory (default: in-place)")
    36  	return cmd
    37  }