diff --git a/cmd/ghcs/logs.go b/cmd/ghcs/logs.go index e35ecb728..4c880725d 100644 --- a/cmd/ghcs/logs.go +++ b/cmd/ghcs/logs.go @@ -14,22 +14,34 @@ import ( ) func newLogsCmd() *cobra.Command { - var tail bool + var ( + codespace string + tail bool + follow bool + ) + + log := output.NewLogger(os.Stdout, os.Stderr, false) logsCmd := &cobra.Command{ - Use: "logs []", + Use: "logs", Short: "Access codespace logs", Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - var codespaceName string if len(args) > 0 { - codespaceName = args[0] + log.Errorln(" argument is deprecated. Use --codespace instead.") + codespace = args[0] } - return logs(context.Background(), tail, codespaceName) + if tail { + log.Errorln("--tail flag is deprecated. Use --follow instead.") + follow = true + } + return logs(context.Background(), log, codespace, follow) }, } - logsCmd.Flags().BoolVarP(&tail, "tail", "t", false, "Tail the logs") + logsCmd.Flags().StringVarP(&codespace, "codespace", "c", "", "Name of the codespace") + logsCmd.Flags().BoolVarP(&tail, "tail", "t", false, "Tail the logs (deprecated, use --follow)") + logsCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Tail and follow the logs") return logsCmd } @@ -38,13 +50,12 @@ func init() { rootCmd.AddCommand(newLogsCmd()) } -func logs(ctx context.Context, tail bool, codespaceName string) error { +func logs(ctx context.Context, log *output.Logger, codespaceName string, follow bool) error { // Ensure all child tasks (port forwarding, remote exec) terminate before return. ctx, cancel := context.WithCancel(ctx) defer cancel() apiClient := api.New(os.Getenv("GITHUB_TOKEN")) - log := output.NewLogger(os.Stdout, os.Stderr, false) user, err := apiClient.GetUser(ctx) if err != nil { @@ -75,7 +86,7 @@ func logs(ctx context.Context, tail bool, codespaceName string) error { } cmdType := "cat" - if tail { + if follow { cmdType = "tail -f" }