mirror of
				https://github.com/juanfont/headscale.git
				synced 2025-11-04 01:51:04 +01:00 
			
		
		
		
	Refactor cmdVersion to cli package
This commit is contained in:
		
							parent
							
								
									5f60671d12
								
							
						
					
					
						commit
						48ec51d166
					
				
							
								
								
									
										23
									
								
								cmd/headscale/cli/version.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								cmd/headscale/cli/version.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					package cli
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var version = "dev"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var VersionCmd = &cobra.Command{
 | 
				
			||||||
 | 
						Use:   "version",
 | 
				
			||||||
 | 
						Short: "Print the version.",
 | 
				
			||||||
 | 
						Long:  "The version of headscale.",
 | 
				
			||||||
 | 
						Run: func(cmd *cobra.Command, args []string) {
 | 
				
			||||||
 | 
							o, _ := cmd.Flags().GetString("output")
 | 
				
			||||||
 | 
							if strings.HasPrefix(o, "json") {
 | 
				
			||||||
 | 
								JsonOutput(map[string]string{"version": version}, nil, o)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							fmt.Println(version)
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -4,28 +4,11 @@ import (
 | 
				
			|||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/juanfont/headscale/cmd/headscale/cli"
 | 
						"github.com/juanfont/headscale/cmd/headscale/cli"
 | 
				
			||||||
	"github.com/spf13/cobra"
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var version = "dev"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var versionCmd = &cobra.Command{
 | 
					 | 
				
			||||||
	Use:   "version",
 | 
					 | 
				
			||||||
	Short: "Print the version.",
 | 
					 | 
				
			||||||
	Long:  "The version of headscale.",
 | 
					 | 
				
			||||||
	Run: func(cmd *cobra.Command, args []string) {
 | 
					 | 
				
			||||||
		o, _ := cmd.Flags().GetString("output")
 | 
					 | 
				
			||||||
		if strings.HasPrefix(o, "json") {
 | 
					 | 
				
			||||||
			cli.JsonOutput(map[string]string{"version": version}, nil, o)
 | 
					 | 
				
			||||||
			return
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		fmt.Println(version)
 | 
					 | 
				
			||||||
	},
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var headscaleCmd = &cobra.Command{
 | 
					var headscaleCmd = &cobra.Command{
 | 
				
			||||||
	Use:   "headscale",
 | 
						Use:   "headscale",
 | 
				
			||||||
	Short: "headscale - a Tailscale control server",
 | 
						Short: "headscale - a Tailscale control server",
 | 
				
			||||||
@ -47,7 +30,7 @@ func main() {
 | 
				
			|||||||
	headscaleCmd.AddCommand(cli.PreauthkeysCmd)
 | 
						headscaleCmd.AddCommand(cli.PreauthkeysCmd)
 | 
				
			||||||
	headscaleCmd.AddCommand(cli.RoutesCmd)
 | 
						headscaleCmd.AddCommand(cli.RoutesCmd)
 | 
				
			||||||
	headscaleCmd.AddCommand(cli.ServeCmd)
 | 
						headscaleCmd.AddCommand(cli.ServeCmd)
 | 
				
			||||||
	headscaleCmd.AddCommand(versionCmd)
 | 
						headscaleCmd.AddCommand(cli.VersionCmd)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cli.NodeCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace")
 | 
						cli.NodeCmd.PersistentFlags().StringP("namespace", "n", "", "Namespace")
 | 
				
			||||||
	err = cli.NodeCmd.MarkPersistentFlagRequired("namespace")
 | 
						err = cli.NodeCmd.MarkPersistentFlagRequired("namespace")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user