mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sterl...@apache.org
Subject incubator-mynewt-newt git commit: add newt new command
Date Fri, 11 Mar 2016 21:24:33 GMT
Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop f74590d09 -> b5850ea23


add newt new command


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/b5850ea2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/b5850ea2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/b5850ea2

Branch: refs/heads/develop
Commit: b5850ea2318d8e4b97d931ec007b87796e8f3b16
Parents: f74590d
Author: Sterling Hughes <sterling@apache.org>
Authored: Fri Mar 11 13:24:20 2016 -0800
Committer: Sterling Hughes <sterling@apache.org>
Committed: Fri Mar 11 13:24:31 2016 -0800

----------------------------------------------------------------------
 newt/cli/project_cmds.go | 48 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/b5850ea2/newt/cli/project_cmds.go
----------------------------------------------------------------------
diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go
index 4392a95..e5df0aa 100644
--- a/newt/cli/project_cmds.go
+++ b/newt/cli/project_cmds.go
@@ -21,14 +21,50 @@ package cli
 
 import (
 	"fmt"
+	"os"
 
 	"github.com/spf13/cobra"
+	"mynewt.apache.org/newt/newt/downloader"
 	"mynewt.apache.org/newt/newt/interfaces"
 	"mynewt.apache.org/newt/newt/project"
+	"mynewt.apache.org/newt/util"
 )
 
 var projectForce bool = false
 
+func newRunCmd(cmd *cobra.Command, args []string) {
+	if len(args) < 1 {
+		NewtUsage(cmd, util.NewNewtError("Must specify "+
+			"a project directory to newt new"))
+	}
+
+	newDir := args[0]
+
+	util.StatusMessage(util.VERBOSITY_DEFAULT, "Downloading "+
+		"project skeleton from apache/incubator-mynewt-blinky...\n")
+	dl := downloader.NewGithubDownloader()
+	dl.User = "apache"
+	dl.Repo = "incubator-mynewt-blinky"
+
+	dir, err := dl.DownloadRepo("develop")
+	if err != nil {
+		NewtUsage(cmd, err)
+	}
+
+	util.StatusMessage(util.VERBOSITY_DEFAULT, "Installing "+
+		"skeleton in %s...\n", newDir)
+
+	if err := util.CopyDir(dir, newDir); err != nil {
+		NewtUsage(cmd, err)
+	}
+
+	if err := os.RemoveAll(newDir + "/" + "/.git/"); err != nil {
+		NewtUsage(cmd, err)
+	}
+
+	fmt.Printf("Project %s successfully created\n", newDir)
+}
+
 func installRunCmd(cmd *cobra.Command, args []string) {
 	if err := project.Initialize(); err != nil {
 		NewtUsage(cmd, err)
@@ -87,4 +123,16 @@ func AddProjectCommands(cmd *cobra.Command) {
 
 	cmd.AddCommand(upgradeCmd)
 
+	newHelpText := ""
+	newHelpEx := ""
+	newCmd := &cobra.Command{
+		Use:     "new",
+		Short:   "Create a new project",
+		Long:    newHelpText,
+		Example: newHelpEx,
+		Run:     newRunCmd,
+	}
+
+	cmd.AddCommand(newCmd)
+
 }


Mime
View raw message