Skip to content

Commit

Permalink
Expose DeleteRoute in the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Mar 2, 2023
1 parent 41846ec commit 3608643
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion cmd/headscale/cli/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ func init() {
log.Fatalf(err.Error())
}
routesCmd.AddCommand(disableRouteCmd)

deleteRouteCmd.Flags().Uint64P("route", "r", 0, "Route identifier (ID)")
err = deleteRouteCmd.MarkFlagRequired("route")
if err != nil {
log.Fatalf(err.Error())
}
routesCmd.AddCommand(deleteRouteCmd)
}

var routesCmd = &cobra.Command{
Expand Down Expand Up @@ -200,7 +207,50 @@ var disableRouteCmd = &cobra.Command{
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Cannot enable route %d: %s", routeID, status.Convert(err).Message()),
fmt.Sprintf("Cannot disable route %d: %s", routeID, status.Convert(err).Message()),
output,
)

return
}

if output != "" {
SuccessOutput(response, "", output)

return
}
},
}

var deleteRouteCmd = &cobra.Command{
Use: "delete",
Short: "Delete a given route",
Long: `This command will delete a given route.`,
Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")

routeID, err := cmd.Flags().GetUint64("route")
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Error getting machine id from flag: %s", err),
output,
)

return
}

ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
defer conn.Close()

response, err := client.DeleteRoute(ctx, &v1.DeleteRouteRequest{
RouteId: routeID,
})
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Cannot delete route %d: %s", routeID, status.Convert(err).Message()),
output,
)

Expand Down

0 comments on commit 3608643

Please sign in to comment.