Skip to content

Commit 1cf9583

Browse files
committed
♻️ Refactor flag usage and mcp logging
issue #64
1 parent 57ee17b commit 1cf9583

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

cmd/auth.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8+
const (
9+
authShort = "Authenticate with YouTube API"
10+
authLong = "Authenticate with YouTube API to access and manage YouTube resources."
11+
credUsage = "Path to client secret file, or base64 encoded string, or json string"
12+
cacheUsage = "Path to token cache file, or base64 encoded string, or json string"
13+
)
14+
815
var (
916
credential string
1017
cacheToken string
1118
)
1219

1320
var authCmd = &cobra.Command{
1421
Use: "auth",
15-
Short: "Authenticate with YouTube API",
16-
Long: "Authenticate with YouTube API",
22+
Short: authShort,
23+
Long: authLong,
1724
Run: func(cmd *cobra.Command, args []string) {
1825
auth.NewY2BService(
1926
auth.WithCredential(credential),
@@ -27,11 +34,9 @@ func init() {
2734
RootCmd.AddCommand(authCmd)
2835

2936
authCmd.Flags().StringVarP(
30-
&credential, "credential", "c", "client_secret.json",
31-
"Path to client secret file, or base64 encoded string, or json string",
37+
&credential, "credential", "c", "client_secret.json", credUsage,
3238
)
3339
authCmd.Flags().StringVarP(
34-
&cacheToken, "cacheToken", "t", "youtube.token.json",
35-
"Path to token cache file, or base64 encoded string, or json string",
40+
&cacheToken, "cacheToken", "t", "youtube.token.json", cacheUsage,
3641
)
3742
}

cmd/mcp.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
)
1010

1111
const (
12+
mcpShort = "Start MCP server"
13+
mcpLong = "Start MCP server to handle requests from clients"
1214
modeUsage = "stdio, http, or sse"
1315
portUsage = "Port to listen on for HTTP or SSE mode"
1416
)
@@ -21,19 +23,20 @@ var (
2123
var MCP = server.NewMCPServer(
2224
"yutu", Version,
2325
server.WithToolCapabilities(true),
26+
server.WithLogging(),
2427
server.WithRecovery(),
2528
)
2629

2730
var mcpCmd = &cobra.Command{
2831
Use: "mcp",
29-
Short: "Start mcp server",
30-
Long: "Start mcp server to handle requests from clients",
32+
Short: mcpShort,
33+
Long: mcpLong,
3134
Run: func(cmd *cobra.Command, args []string) {
3235
var err error
3336
interval := 13 * time.Second
3437
addr := fmt.Sprintf(":%d", port)
3538
baseURL := fmt.Sprintf("http://localhost:%d", port)
36-
message := fmt.Sprintf("Starting MCP server: %s", baseURL)
39+
message := fmt.Sprintf("%s server listening on %s", mode, addr)
3740

3841
switch mode {
3942
case "stdio":
@@ -56,7 +59,7 @@ var mcpCmd = &cobra.Command{
5659
}
5760

5861
if err != nil {
59-
fmt.Printf("Server error: %v\n", err)
62+
log.Fatalf("Server error: %v\n", err)
6063
}
6164
},
6265
}

cmd/root.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import (
77
"github.com/spf13/viper"
88
)
99

10+
const (
11+
short = "A fully functional CLI for YouTube"
12+
long = "yutu is a fully functional CLI for YouTube, which can be used to manipulate YouTube videos, playlists, channels, etc"
13+
)
14+
1015
var RootCmd = &cobra.Command{
1116
Use: "yutu",
12-
Short: "A fully functional CLI for YouTube",
13-
Long: "yutu is a fully functional CLI for YouTube, which can be used to manipulate YouTube videos, playlists, channels, etc.",
17+
Short: short,
18+
Long: long,
1419

1520
Run: func(cmd *cobra.Command, args []string) {
1621
_ = cmd.Help()

cmd/version.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8+
const (
9+
versionShort = "Show the version of yutu"
10+
versionLong = "Show the version of yutu"
11+
)
12+
813
var (
914
Version = ""
1015
Commit = ""
@@ -16,8 +21,8 @@ var (
1621

1722
var versionCmd = &cobra.Command{
1823
Use: "version",
19-
Short: "Show the version of yutu",
20-
Long: "Show the version of yutu",
24+
Short: versionShort,
25+
Long: versionLong,
2126
Run: func(cmd *cobra.Command, args []string) {
2227
cmd.Printf("yutu🐰 version %s %s/%s", Version, Os, Arch)
2328
if Commit != "" && CommitDate != "" {

0 commit comments

Comments
 (0)