Add and fix nlreturn (new line return)
This commit is contained in:
parent
d0ef850035
commit
89eb13c6cb
25 changed files with 198 additions and 1 deletions
|
@ -48,6 +48,7 @@ var createNodeCmd = &cobra.Command{
|
|||
namespace, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -62,6 +63,7 @@ var createNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error getting node from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -72,6 +74,7 @@ var createNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error getting key from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -82,6 +85,7 @@ var createNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error getting routes from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -99,6 +103,7 @@ var createNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot create machine: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ var createNamespaceCmd = &cobra.Command{
|
|||
if len(args) < 1 {
|
||||
return fmt.Errorf("Missing parameters")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -57,6 +58,7 @@ var createNamespaceCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -71,6 +73,7 @@ var destroyNamespaceCmd = &cobra.Command{
|
|||
if len(args) < 1 {
|
||||
return fmt.Errorf("Missing parameters")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -93,6 +96,7 @@ var destroyNamespaceCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -124,6 +128,7 @@ var destroyNamespaceCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
SuccessOutput(response, "Namespace destroyed", output)
|
||||
|
@ -152,11 +157,13 @@ var listNamespacesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot get namespaces: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
SuccessOutput(response.Namespaces, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -178,6 +185,7 @@ var listNamespacesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Failed to render pterm table: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -190,6 +198,7 @@ var renameNamespaceCmd = &cobra.Command{
|
|||
if len(args) < 2 {
|
||||
return fmt.Errorf("Missing parameters")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -214,6 +223,7 @@ var renameNamespaceCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ var registerNodeCmd = &cobra.Command{
|
|||
namespace, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -91,6 +92,7 @@ var registerNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error getting machine key from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -109,6 +111,7 @@ var registerNodeCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -124,6 +127,7 @@ var listNodesCmd = &cobra.Command{
|
|||
namespace, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -142,17 +146,20 @@ var listNodesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot get nodes: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
SuccessOutput(response.Machines, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
d, err := nodesToPtables(namespace, response.Machines)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -163,6 +170,7 @@ var listNodesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Failed to render pterm table: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -181,6 +189,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error converting ID to integer: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -202,6 +211,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -228,6 +238,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||
response, err := client.DeleteMachine(ctx, deleteRequest)
|
||||
if output != "" {
|
||||
SuccessOutput(response, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -239,6 +250,7 @@ var deleteNodeCmd = &cobra.Command{
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
SuccessOutput(
|
||||
|
@ -260,6 +272,7 @@ func sharingWorker(
|
|||
namespaceStr, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -270,6 +283,7 @@ func sharingWorker(
|
|||
id, err := cmd.Flags().GetInt("identifier")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error converting ID to integer: %s", err), output)
|
||||
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -284,6 +298,7 @@ func sharingWorker(
|
|||
fmt.Sprintf("Error getting node node: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -298,6 +313,7 @@ func sharingWorker(
|
|||
fmt.Sprintf("Error getting node node: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return "", nil, nil, err
|
||||
}
|
||||
|
||||
|
@ -315,6 +331,7 @@ var shareMachineCmd = &cobra.Command{
|
|||
fmt.Sprintf("Failed to fetch namespace or machine: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -334,6 +351,7 @@ var shareMachineCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error sharing node: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -352,6 +370,7 @@ var unshareMachineCmd = &cobra.Command{
|
|||
fmt.Sprintf("Failed to fetch namespace or machine: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -371,6 +390,7 @@ var unshareMachineCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error unsharing node: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -442,5 +462,6 @@ func nodesToPtables(
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||
n, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -62,11 +63,13 @@ var listPreAuthKeys = &cobra.Command{
|
|||
fmt.Sprintf("Error getting the list of keys: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
SuccessOutput(response.PreAuthKeys, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -104,6 +107,7 @@ var listPreAuthKeys = &cobra.Command{
|
|||
fmt.Sprintf("Failed to render pterm table: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -118,6 +122,7 @@ var createPreAuthKeyCmd = &cobra.Command{
|
|||
namespace, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -156,6 +161,7 @@ var createPreAuthKeyCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot create Pre Auth Key: %s\n", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -170,6 +176,7 @@ var expirePreAuthKeyCmd = &cobra.Command{
|
|||
if len(args) < 1 {
|
||||
return fmt.Errorf("missing parameters")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
@ -177,6 +184,7 @@ var expirePreAuthKeyCmd = &cobra.Command{
|
|||
namespace, err := cmd.Flags().GetString("namespace")
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error getting namespace: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -196,6 +204,7 @@ var expirePreAuthKeyCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot expire Pre Auth Key: %s\n", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ var listRoutesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Error getting machine id from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,17 +71,20 @@ var listRoutesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Cannot get nodes: %s", status.Convert(err).Message()),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
SuccessOutput(response.Routes, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
d := routesToPtables(response.Routes)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -91,6 +95,7 @@ var listRoutesCmd = &cobra.Command{
|
|||
fmt.Sprintf("Failed to render pterm table: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -113,6 +118,7 @@ omit the route you do not want to enable.
|
|||
fmt.Sprintf("Error getting machine id from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -123,6 +129,7 @@ omit the route you do not want to enable.
|
|||
fmt.Sprintf("Error getting routes from flag: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -145,17 +152,20 @@ omit the route you do not want to enable.
|
|||
),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if output != "" {
|
||||
SuccessOutput(response.Routes, "", output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
d := routesToPtables(response.Routes)
|
||||
if err != nil {
|
||||
ErrorOutput(err, fmt.Sprintf("Error converting to table: %s", err), output)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -166,6 +176,7 @@ omit the route you do not want to enable.
|
|||
fmt.Sprintf("Failed to render pterm table: %s", err),
|
||||
output,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
},
|
||||
|
@ -180,6 +191,7 @@ func routesToPtables(routes *v1.Routes) pterm.TableData {
|
|||
|
||||
d = append(d, []string{route, strconv.FormatBool(enabled)})
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,7 @@ func absPath(path string) string {
|
|||
path = filepath.Join(dir, path)
|
||||
}
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
|
@ -310,6 +311,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) {
|
|||
viper.GetString("ephemeral_node_inactivity_timeout"),
|
||||
minInactivityTimeout,
|
||||
)
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -415,6 +417,7 @@ func SuccessOutput(result interface{}, override string, outputFormat string) {
|
|||
}
|
||||
default:
|
||||
fmt.Println(override)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -435,6 +438,7 @@ func HasMachineOutputFlag() bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue