Add periods at the end of descriptions. Refactor position and naming
@@ -32,11 +32,38 @@ type FlagsStatus struct {
var statusFlags = FlagsStatus{}
+var Command = &command.Command{
+ Cmd: &cobra.Command{
+ Use: "status",
+ Short: "Display the status of the Flow network",
+ },
+ Flags: &statusFlags,
+ Run: func(
+ cmd *cobra.Command,
+ args []string,
+ globalFlags command.GlobalFlags,
+ services *services.Services,
+ ) (command.Result, error) {
+ // Get network name from global flag
+ network := globalFlags.Network
+ if network == "" {
+ network = command.NetworkEmulator
+ }
+
+ accessNode, err := services.Status.Ping(network)
+
+ return &Result{
+ network: network,
+ accessNode: accessNode,
+ err: err,
+ }, nil
+ },
+}
type Result struct {
network string
accessNode string
- connectionError error
+ err error
}
@@ -48,62 +75,34 @@ const (
OfflineStatus = "OFFLINE"
)
-// getStatus returns string representation for network status
+// getStatus returns string representation for Flow network status.
func (r *Result) getStatus() string {
- if r.connectionError == nil {
+ if r.err == nil {
return OnlineStatus
}
return OfflineStatus
}
-// getColoredStatus returns colored string representation for network status
+// getColoredStatus returns colored string representation for Flow network status.
func (r *Result) getColoredStatus() string {
- if r.connectionError == nil {
+ if r.err == nil {
return util.Green(OnlineStatus)
}
return util.Red(OfflineStatus)
}
-// getIcon returns emoji icon representing network statu
+// getIcon returns emoji icon representing Flow network status.
func (r *Result) getIcon() string {
- if r.connectionError == nil {
+ if r.err == nil {
return OnlineIcon
}
return OfflineIcon
}
-var InitCommand = &command.Command{
- Cmd: &cobra.Command{
- Use: "status",
- Short: "Display status of network",
- },
- Flags: &statusFlags,
- Run: func(
- cmd *cobra.Command,
- args []string,
- globalFlags command.GlobalFlags,
- services *services.Services,
- ) (command.Result, error) {
- // Get network name from global flag
- network := globalFlags.Network
- if network == "" {
- network = "emulator"
- }
-
- accessNode, err := services.Status.Ping(network)
-
- return &Result{
- network: network,
- accessNode: accessNode,
- connectionError: err,
- }, nil
- },
-}
-
-// String convert result to string
+// String converts result to a string.
func (r *Result) String() string {
var b bytes.Buffer
writer := util.CreateTabWriter(&b)
@@ -116,7 +115,7 @@ func (r *Result) String() string {
return b.String()
}
-// JSON convert result to JSON
+// JSON converts result to a JSON.
func (r *Result) JSON() interface{} {
result := make(map[string]string)
@@ -127,7 +126,7 @@ func (r *Result) JSON() interface{} {
return result
}
-// Oneliner show result as one liner grep friendly
+// Oneliner returns result as one liner grep friendly.
func (r *Result) Oneliner() string {
return r.getStatus()
}
