You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/06/10 23:31:08 UTC
[1/4] incubator-mynewt-newt git commit: Factor out common code that
creates connection to target device
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop 3494f8141 -> d82b2eb0e
Factor out common code that creates connection to target device
Create getTargetCmdRunner() function that refactors out common code
used by each command to establish a connection to the target device.
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/82da626d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/82da626d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/82da626d
Branch: refs/heads/develop
Commit: 82da626d4b8db5c65996a86056bc12c167350794
Parents: a6b6431
Author: Gordon Chaffee <go...@runtime.io>
Authored: Wed Feb 24 11:22:26 2016 -0800
Committer: Gordon Chaffee <go...@runtime.io>
Committed: Wed Feb 24 11:26:18 2016 -0800
----------------------------------------------------------------------
newtmgr/cli/common.go | 30 +++++++++++++++
newtmgr/cli/config.go | 18 +--------
newtmgr/cli/echo.go | 19 +---------
newtmgr/cli/image.go | 87 +++----------------------------------------
newtmgr/cli/logs.go | 36 +-----------------
newtmgr/cli/mpstats.go | 19 +---------
newtmgr/cli/stats.go | 19 +---------
newtmgr/cli/taskstats.go | 19 +---------
8 files changed, 42 insertions(+), 205 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/common.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/common.go b/newtmgr/cli/common.go
new file mode 100644
index 0000000..7bc7423
--- /dev/null
+++ b/newtmgr/cli/common.go
@@ -0,0 +1,30 @@
+package cli
+
+import (
+ "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
+ "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
+ "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
+)
+
+func getTargetCmdRunner() (*protocol.CmdRunner, error) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ return nil, err
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ return nil, err
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ return nil, err
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ return nil, err
+ }
+ return runner, nil
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/config.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/config.go b/newtmgr/cli/config.go
index 3cff1e7..8fec370 100644
--- a/newtmgr/cli/config.go
+++ b/newtmgr/cli/config.go
@@ -3,9 +3,7 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
"github.com/spf13/cobra"
)
@@ -14,22 +12,8 @@ func configRunCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
nmUsage(cmd, util.NewNewtError("Need variable name"))
}
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/echo.go b/newtmgr/cli/echo.go
index b4aa3f8..09d3cb1 100644
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@ -3,29 +3,12 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func echoRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 40f034f..150c41a 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -6,30 +6,13 @@ import (
"io/ioutil"
"os"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
"github.com/spf13/cobra"
)
func imageListCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -73,22 +56,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, util.NewNewtError(err.Error()))
}
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -143,22 +111,7 @@ func imageUploadCmd(cmd *cobra.Command, args []string) {
}
func imageBootCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -212,22 +165,7 @@ func fileUploadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, util.NewNewtError("Target filename too long"))
}
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -300,22 +238,7 @@ func fileDownloadCmd(cmd *cobra.Command, args []string) {
nmUsage(cmd, util.NewNewtError("Target filename too long"))
}
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index e17374c..c7c1d35 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -3,29 +3,12 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func logsShowCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -59,22 +42,7 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
}
func logsClearCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/mpstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/mpstats.go b/newtmgr/cli/mpstats.go
index 2600e9b..3abee74 100644
--- a/newtmgr/cli/mpstats.go
+++ b/newtmgr/cli/mpstats.go
@@ -3,29 +3,12 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func mempoolStatsRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/stats.go b/newtmgr/cli/stats.go
index 8d908c8..1e4d53d 100644
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@ -3,29 +3,12 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func statsRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/82da626d/newtmgr/cli/taskstats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/taskstats.go b/newtmgr/cli/taskstats.go
index 16adcb0..b4a344b 100644
--- a/newtmgr/cli/taskstats.go
+++ b/newtmgr/cli/taskstats.go
@@ -3,29 +3,12 @@ package cli
import (
"fmt"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
"git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func taskStatsRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
[4/4] incubator-mynewt-newt git commit: newtmgr cli;
use getTargetCmdRunner() convenience routine.
Posted by ma...@apache.org.
newtmgr cli; use getTargetCmdRunner() convenience routine.
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/d82b2eb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/d82b2eb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/d82b2eb0
Branch: refs/heads/develop
Commit: d82b2eb0e938847afcd0cf55c0482dfdc6b877b4
Parents: f83a97b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jun 10 16:29:48 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jun 10 16:29:48 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/datetime.go | 19 +---------
newtmgr/cli/image.go | 85 +++-----------------------------------------
newtmgr/cli/logs.go | 53 ++-------------------------
newtmgr/cli/reset.go | 19 +---------
newtmgr/cli/stats.go | 19 +---------
5 files changed, 11 insertions(+), 184 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d82b2eb0/newtmgr/cli/datetime.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/datetime.go b/newtmgr/cli/datetime.go
index da0a2a9..88632cf 100644
--- a/newtmgr/cli/datetime.go
+++ b/newtmgr/cli/datetime.go
@@ -23,29 +23,12 @@ import (
"fmt"
"github.com/spf13/cobra"
- "mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
"mynewt.apache.org/newt/util"
)
func dateTimeCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d82b2eb0/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index ba9748d..c56a884 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -86,22 +86,7 @@ func imageListCmd(cmd *cobra.Command, args []string) {
}
func imageListCmd2(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(nil, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -286,22 +271,7 @@ func imageBootCmd(cmd *cobra.Command, args []string) {
}
func imageBoot2Cmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(nil, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -496,22 +466,7 @@ func coreDownloadCmd(cmd *cobra.Command, args []string) {
return
}
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -573,22 +528,7 @@ func coreDownloadCmd(cmd *cobra.Command, args []string) {
}
func coreListCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -626,22 +566,7 @@ func coreListCmd(cmd *cobra.Command, args []string) {
}
func coreEraseCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d82b2eb0/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/logs.go b/newtmgr/cli/logs.go
index f75605e..86952c9 100644
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@ -23,9 +23,7 @@ import (
"fmt"
"strconv"
- "mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
"github.com/spf13/cobra"
)
@@ -174,22 +172,7 @@ func logsShowCmd(cmd *cobra.Command, args []string) {
}
func logsModuleListCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -224,22 +207,7 @@ func logsModuleListCmd(cmd *cobra.Command, args []string) {
}
func logsListCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
@@ -273,22 +241,7 @@ func logsListCmd(cmd *cobra.Command, args []string) {
}
func logsLevelListCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d82b2eb0/newtmgr/cli/reset.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/reset.go b/newtmgr/cli/reset.go
index e477b4a..8710a63 100644
--- a/newtmgr/cli/reset.go
+++ b/newtmgr/cli/reset.go
@@ -23,28 +23,11 @@ import (
"fmt"
"github.com/spf13/cobra"
- "mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
)
func resetRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/d82b2eb0/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/stats.go b/newtmgr/cli/stats.go
index 872e00b..6014797 100644
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@ -22,30 +22,13 @@ package cli
import (
"fmt"
- "mynewt.apache.org/newt/newtmgr/config"
"mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
"github.com/spf13/cobra"
)
func statsListRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
[2/4] incubator-mynewt-newt git commit: This closes #5.
Posted by ma...@apache.org.
This closes #5.
Merge branch 'refactor_common_connect' of https://github.com/gordonchaffee/incubator-mynewt-newt into develop
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/dccd34ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/dccd34ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/dccd34ef
Branch: refs/heads/develop
Commit: dccd34ef798d7f12cc86df817d4010af6e0f110e
Parents: 3494f81 82da626
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jun 10 16:13:31 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jun 10 16:13:31 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/common.go | 30 +++++++++++++++++++++++++
newtmgr/cli/config.go | 18 +--------------
newtmgr/cli/echo.go | 19 +---------------
newtmgr/cli/image.go | 51 +++----------------------------------------
newtmgr/cli/logs.go | 37 ++++---------------------------
newtmgr/cli/mpstats.go | 19 +---------------
newtmgr/cli/stats.go | 17 +--------------
newtmgr/cli/taskstats.go | 19 +---------------
8 files changed, 42 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/common.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/common.go
index 0000000,7bc7423..f6e16d9
mode 000000,100644..100644
--- a/newtmgr/cli/common.go
+++ b/newtmgr/cli/common.go
@@@ -1,0 -1,30 +1,30 @@@
+ package cli
+
+ import (
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/config"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/transport"
++ "mynewt.apache.org/newt/newtmgr/config"
++ "mynewt.apache.org/newt/newtmgr/protocol"
++ "mynewt.apache.org/newt/newtmgr/transport"
+ )
+
+ func getTargetCmdRunner() (*protocol.CmdRunner, error) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ return nil, err
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ return nil, err
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ return nil, err
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ return nil, err
+ }
+ return runner, nil
+ }
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/config.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/config.go
index 76a8c07,8fec370..13bb6ca
--- a/newtmgr/cli/config.go
+++ b/newtmgr/cli/config.go
@@@ -22,11 -3,8 +22,9 @@@ package cl
import (
"fmt"
- "mynewt.apache.org/newt/newtmgr/config"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/util"
+ "mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
+ "mynewt.apache.org/newt/util"
+
"github.com/spf13/cobra"
)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/echo.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/echo.go
index bdcafcc,09d3cb1..9f6f189
--- a/newtmgr/cli/echo.go
+++ b/newtmgr/cli/echo.go
@@@ -22,10 -3,7 +22,8 @@@ package cl
import (
"fmt"
- "mynewt.apache.org/newt/newtmgr/config"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
+ "mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
+
"github.com/spf13/cobra"
)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/image.go
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/logs.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/logs.go
index 2f567d8,c7c1d35..f75605e
--- a/newtmgr/cli/logs.go
+++ b/newtmgr/cli/logs.go
@@@ -21,112 -2,13 +21,98 @@@ package cl
import (
"fmt"
+ "strconv"
+
- "github.com/spf13/cobra"
+ "mynewt.apache.org/newt/newtmgr/config"
+ "mynewt.apache.org/newt/newtmgr/protocol"
+ "mynewt.apache.org/newt/newtmgr/transport"
+
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
+ "github.com/spf13/cobra"
)
+const (
+ LEVEL_DEBUG uint64 = 0
+ LEVEL_INFO uint64 = 1
+ LEVEL_WARN uint64 = 2
+ LEVEL_ERROR uint64 = 3
+ LEVEL_CRITICAL uint64 = 4
+ /* Upto 7 custom loglevels */
+ LEVEL_MAX uint64 = 255
+)
+
+const (
+ STREAM_LOG uint64 = 0
+ MEMORY_LOG uint64 = 1
+ STORAGE_LOG uint64 = 2
+)
+
+const (
+ MODULE_DEFAULT uint64 = 0
+ MODULE_OS uint64 = 1
+ MODULE_NEWTMGR uint64 = 2
+ MODULE_NIMBLE_CTLR uint64 = 3
+ MODULE_NIMBLE_HOST uint64 = 4
+ MODULE_NFFS uint64 = 5
+ MODULE_MAX uint64 = 255
+)
+
+func LogModuleToString(lm uint64) string {
+ s := ""
+ switch lm {
+ case MODULE_DEFAULT:
+ s = "DEFAULT"
+ case MODULE_OS:
+ s = "OS"
+ case MODULE_NEWTMGR:
+ s = "NEWTMGR"
+ case MODULE_NIMBLE_CTLR:
+ s = "NIMBLE_CTLR"
+ case MODULE_NIMBLE_HOST:
+ s = "NIMBLE_HOST"
+ case MODULE_NFFS:
+ s = "NFFS"
+ default:
+ s = "CUSTOM"
+ }
+ return s
+}
+
+func LoglevelToString(ll uint64) string {
+ s := ""
+ switch ll {
+ case LEVEL_DEBUG:
+ s = "DEBUG"
+ case LEVEL_INFO:
+ s = "INFO"
+ case LEVEL_WARN:
+ s = "WARN"
+ case LEVEL_ERROR:
+ s = "ERROR"
+ case LEVEL_CRITICAL:
+ s = "CRITICAL"
+ default:
+ s = "CUSTOM"
+ }
+ return s
+}
+
+func LogTypeToString(lt uint64) string {
+ s := ""
+ switch lt {
+ case STREAM_LOG:
+ s = "STREAM"
+ case MEMORY_LOG:
+ s = "MEMORY"
+ case STORAGE_LOG:
+ s = "STORAGE"
+ default:
+ s = "UNDEFINED"
+ }
+ return s
+}
+
func logsShowCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/mpstats.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/mpstats.go
index 24cae5e,3abee74..3dc7772
--- a/newtmgr/cli/mpstats.go
+++ b/newtmgr/cli/mpstats.go
@@@ -22,10 -3,7 +22,8 @@@ package cl
import (
"fmt"
- "mynewt.apache.org/newt/newtmgr/config"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
+ "mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
+
"github.com/spf13/cobra"
)
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/stats.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/stats.go
index 714a0bb,1e4d53d..872e00b
--- a/newtmgr/cli/stats.go
+++ b/newtmgr/cli/stats.go
@@@ -29,72 -7,8 +29,57 @@@ import
"github.com/spf13/cobra"
)
+func statsListRunCmd(cmd *cobra.Command, args []string) {
+ cpm, err := config.NewConnProfileMgr()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ profile, err := cpm.GetConnProfile(ConnProfileName)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ conn, err := transport.NewConn(profile)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ runner, err := protocol.NewCmdRunner(conn)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ slr, err := protocol.NewStatsListReq()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ nmr, err := slr.Encode()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ if err := runner.WriteReq(nmr); err != nil {
+ nmUsage(cmd, err)
+ }
+
+ rsp, err := runner.ReadResp()
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ slrsp, err := protocol.DecodeStatsListResponse(rsp.Data)
+ if err != nil {
+ nmUsage(cmd, err)
+ }
+
+ fmt.Println(slrsp.List)
+ fmt.Printf("Return Code = %d\n", slrsp.ReturnCode)
+}
+
func statsRunCmd(cmd *cobra.Command, args []string) {
- cpm, err := config.NewConnProfileMgr()
- if err != nil {
- nmUsage(cmd, err)
- }
-
- profile, err := cpm.GetConnProfile(ConnProfileName)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- conn, err := transport.NewConn(profile)
- if err != nil {
- nmUsage(cmd, err)
- }
-
- runner, err := protocol.NewCmdRunner(conn)
+ runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/dccd34ef/newtmgr/cli/taskstats.go
----------------------------------------------------------------------
diff --cc newtmgr/cli/taskstats.go
index 228fa59,b4a344b..e36f988
--- a/newtmgr/cli/taskstats.go
+++ b/newtmgr/cli/taskstats.go
@@@ -22,10 -3,7 +22,8 @@@ package cl
import (
"fmt"
- "mynewt.apache.org/newt/newtmgr/config"
- "git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/newtmgr/protocol"
+ "mynewt.apache.org/newt/newtmgr/protocol"
- "mynewt.apache.org/newt/newtmgr/transport"
+
"github.com/spf13/cobra"
)
[3/4] incubator-mynewt-newt git commit: newtmgr cli/common;
add license header.
Posted by ma...@apache.org.
newtmgr cli/common; add license header.
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/f83a97b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/f83a97b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/f83a97b2
Branch: refs/heads/develop
Commit: f83a97b23c8d38c3eb15e98afd00e00434a4899f
Parents: dccd34e
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Jun 10 16:14:30 2016 -0700
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Jun 10 16:14:30 2016 -0700
----------------------------------------------------------------------
newtmgr/cli/common.go | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/f83a97b2/newtmgr/cli/common.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/common.go b/newtmgr/cli/common.go
index f6e16d9..eefa5c9 100644
--- a/newtmgr/cli/common.go
+++ b/newtmgr/cli/common.go
@@ -1,3 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package cli
import (