Skip to content

Commit 2543222

Browse files
committed
♻️ Refactor flag usage for mcp
issue #64
1 parent 379e9f3 commit 2543222

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+982
-821
lines changed

cmd/activity/activity.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
)
88

99
const (
10-
shortUsage = "List YouTube activities"
11-
longUsage = "List YouTube activities"
12-
channelIdUsage = "ID of the channel"
13-
homeUsage = "true or false or empty"
14-
maxResultsUsage = "The maximum number of items that should be returned"
15-
mineUsage = "true or false or empty"
16-
publishedAfterUsage = "Filter on activities published after this date"
17-
publishedBeforeUsage = "Filter on activities published before this date"
18-
regionCodeUsage = ""
19-
partsUsage = "Comma separated parts"
20-
outputUsage = "json or yaml"
10+
short = "List YouTube activities"
11+
long = "List YouTube activities, such as likes, favorites, uploads, etc"
12+
ciUsage = "ID of the channel"
13+
homeUsage = "true, false, or empty"
14+
mrUsage = "The maximum number of items that should be returned"
15+
mineUsage = "true, false, or empty"
16+
paUsage = "Filter on activities published after this date"
17+
pbUsage = "Filter on activities published before this date"
18+
rcUsage = ""
19+
partsUsage = "Comma separated parts"
20+
outputUsage = "json or yaml"
2121
)
2222

2323
var (
@@ -34,8 +34,8 @@ var (
3434

3535
var activityCmd = &cobra.Command{
3636
Use: "activity",
37-
Short: shortUsage,
38-
Long: longUsage,
37+
Short: short,
38+
Long: long,
3939
PersistentPreRun: func(cmd *cobra.Command, args []string) {
4040
boolMap := map[string]*bool{
4141
"home": home,

cmd/activity/list.go

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,35 @@ import (
1111
"io"
1212
)
1313

14-
const (
15-
listShortUsage = "List YouTube activities"
16-
listLongUsage = "List YouTube activities, such as likes, favorites, uploads, etc."
17-
)
18-
1914
var defaultParts = []string{"id", "snippet", "contentDetails"}
2015

2116
var listTool = mcp.NewTool(
2217
"activity.list",
23-
mcp.WithDescription(listLongUsage),
18+
mcp.WithDescription(long),
2419
mcp.WithString(
25-
"channelId", mcp.DefaultString(""), mcp.Description(channelIdUsage),
20+
"channelId", mcp.DefaultString(""), mcp.Description(ciUsage),
2621
),
2722
mcp.WithString(
2823
"home", mcp.Enum("true", "false", ""),
2924
mcp.DefaultString(""), mcp.Description(homeUsage),
3025
),
3126
mcp.WithNumber(
32-
"maxResults", mcp.DefaultNumber(5), mcp.Description(maxResultsUsage),
27+
"maxResults", mcp.DefaultNumber(5), mcp.Description(mrUsage),
3328
),
3429
mcp.WithString(
3530
"mine", mcp.Enum("true", "false", ""),
3631
mcp.DefaultString("true"), mcp.Description(mineUsage),
3732
),
3833
mcp.WithString(
3934
"publishedAfter", mcp.DefaultString(""),
40-
mcp.Description(publishedAfterUsage),
35+
mcp.Description(paUsage),
4136
),
4237
mcp.WithString(
4338
"publishedBefore", mcp.DefaultString(""),
44-
mcp.Description(publishedBeforeUsage),
39+
mcp.Description(pbUsage),
4540
),
4641
mcp.WithString(
47-
"regionCode", mcp.DefaultString(""), mcp.Description(regionCodeUsage),
42+
"regionCode", mcp.DefaultString(""), mcp.Description(rcUsage),
4843
),
4944
mcp.WithArray(
5045
"parts", mcp.DefaultArray(defaultParts), mcp.Description(partsUsage),
@@ -69,8 +64,8 @@ func run(writer io.Writer) error {
6964

7065
var listCmd = &cobra.Command{
7166
Use: "list",
72-
Short: listShortUsage,
73-
Long: listLongUsage,
67+
Short: short,
68+
Long: long,
7469
Run: func(cmd *cobra.Command, args []string) {
7570
err := run(cmd.OutOrStdout())
7671
if err != nil {
@@ -83,25 +78,18 @@ var listCmd = &cobra.Command{
8378
func init() {
8479
cmd.MCP.AddTool(listTool, listHandler)
8580
activityCmd.AddCommand(listCmd)
86-
listCmd.Flags().StringVarP(
87-
&channelId, "channelId", "c", "", channelIdUsage,
88-
)
81+
listCmd.Flags().StringVarP(&channelId, "channelId", "c", "", ciUsage)
8982
listCmd.Flags().BoolVarP(home, "home", "H", true, homeUsage)
90-
listCmd.Flags().Int64VarP(
91-
&maxResults, "maxResults", "n", 5, maxResultsUsage,
92-
)
83+
listCmd.Flags().Int64VarP(&maxResults, "maxResults", "n", 5, mrUsage)
9384
listCmd.Flags().BoolVarP(mine, "mine", "M", true, mineUsage)
9485
listCmd.Flags().StringVarP(
95-
&publishedAfter, "publishedAfter", "a", "", publishedAfterUsage,
86+
&publishedAfter, "publishedAfter", "a", "", paUsage,
9687
)
9788
listCmd.Flags().StringVarP(
98-
&publishedBefore, "publishedBefore", "b", "", publishedBeforeUsage,
99-
)
100-
listCmd.Flags().StringVarP(&regionCode, "regionCode", "r", "", regionCodeUsage)
101-
102-
listCmd.Flags().StringArrayVarP(
103-
&parts, "parts", "p", defaultParts, partsUsage,
89+
&publishedBefore, "publishedBefore", "b", "", pbUsage,
10490
)
91+
listCmd.Flags().StringVarP(&regionCode, "regionCode", "r", "", rcUsage)
92+
listCmd.Flags().StringArrayVarP(&parts, "parts", "p", defaultParts, partsUsage)
10593
listCmd.Flags().StringVarP(&output, "output", "o", "", outputUsage)
10694
}
10795

cmd/caption/caption.go

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

10+
const (
11+
short = "Manipulate YouTube captions"
12+
long = "List, insert, update, download, or delete YouTube captions"
13+
idUsage = "ID of the caption"
14+
fileUsage = "Path to save the caption file"
15+
attUsage = "unknown, primary, commentary, or descriptive"
16+
iasUsage = "Whether YouTube synchronized the caption track to the audio track in the video"
17+
iscUsage = "Whether the track contains closed captions for the deaf and hard of hearing"
18+
isdUsage = "whether the caption track is a draft"
19+
iserUsage = "Whether caption track is formatted for 'easy reader'"
20+
islUsage = "Whether the caption track uses large text for the vision-impaired"
21+
languageUsage = "Language of the caption track"
22+
nameUsage = "Name of the caption track"
23+
tkUsage = "standard, ASR, or forced"
24+
vidUsage = "ID of the video"
25+
partsUsage = "Comma separated parts"
26+
tfmtUsage = "sbv, srt, or vtt"
27+
tlangUsage = "Translate the captions into this language"
28+
)
29+
1030
var (
1131
id string
1232
file string
@@ -30,8 +50,8 @@ var (
3050

3151
var captionCmd = &cobra.Command{
3252
Use: "caption",
33-
Short: "Manipulate YouTube captions",
34-
Long: "List, insert, update, download, or delete YouTube captions",
53+
Short: short,
54+
Long: long,
3555
PersistentPreRun: func(cmd *cobra.Command, args []string) {
3656
resetFlags(cmd.Flags())
3757
},

cmd/caption/delete.go

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

8+
const (
9+
deleteShort = "Delete caption"
10+
deleteLong = "Delete caption of a video"
11+
)
12+
813
var deleteCmd = &cobra.Command{
914
Use: "delete",
10-
Short: "Delete caption",
11-
Long: "Delete caption of a video",
15+
Short: deleteShort,
16+
Long: deleteLong,
1217
Run: func(cmd *cobra.Command, args []string) {
1318
c := caption.NewCation(
1419
caption.WithID(id),
@@ -23,7 +28,7 @@ var deleteCmd = &cobra.Command{
2328
func init() {
2429
captionCmd.AddCommand(deleteCmd)
2530

26-
deleteCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the caption")
31+
deleteCmd.Flags().StringVarP(&id, "id", "i", "", idUsage)
2732
deleteCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
2833
deleteCmd.Flags().StringVarP(
2934
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "",

cmd/caption/download.go

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

8+
const (
9+
downloadShort = "Download caption"
10+
downloadLong = "Download caption from a video"
11+
)
12+
813
var downloadCmd = &cobra.Command{
914
Use: "download",
10-
Short: "Download caption",
11-
Long: "Download caption from a video",
15+
Short: downloadShort,
16+
Long: downloadLong,
1217
Run: func(cmd *cobra.Command, args []string) {
1318
c := caption.NewCation(
1419
caption.WithID(id),
@@ -26,14 +31,10 @@ var downloadCmd = &cobra.Command{
2631
func init() {
2732
captionCmd.AddCommand(downloadCmd)
2833

29-
downloadCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the caption")
30-
downloadCmd.Flags().StringVarP(
31-
&file, "file", "f", "", "Path to save the caption file",
32-
)
33-
downloadCmd.Flags().StringVarP(&tfmt, "tfmt", "t", "", "sbv, srt or vtt")
34-
downloadCmd.Flags().StringVarP(
35-
&tlang, "tlang", "l", "", "Translate the captions into this language",
36-
)
34+
downloadCmd.Flags().StringVarP(&id, "id", "i", "", idUsage)
35+
downloadCmd.Flags().StringVarP(&file, "file", "f", "", fileUsage)
36+
downloadCmd.Flags().StringVarP(&tfmt, "tfmt", "t", "", tfmtUsage)
37+
downloadCmd.Flags().StringVarP(&tlang, "tlang", "l", "", tlangUsage)
3738
downloadCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
3839
downloadCmd.Flags().StringVarP(
3940
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "",

cmd/caption/insert.go

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8+
const (
9+
insertShort = "Insert caption"
10+
insertLong = "Insert caption to a video"
11+
insertOutputUsage = "json, yaml, or silent"
12+
)
13+
814
var insertCmd = &cobra.Command{
915
Use: "insert",
10-
Short: "Insert caption",
11-
Long: "Insert caption to a video",
16+
Short: insertShort,
17+
Long: insertLong,
1218
Run: func(cmd *cobra.Command, args []string) {
1319
c := caption.NewCation(
1420
caption.WithFile(file),
@@ -33,47 +39,28 @@ var insertCmd = &cobra.Command{
3339
func init() {
3440
captionCmd.AddCommand(insertCmd)
3541

42+
insertCmd.Flags().StringVarP(&file, "file", "f", "", fileUsage)
3643
insertCmd.Flags().StringVarP(
37-
&file, "file", "f", "", "Path to the caption file",
38-
)
39-
insertCmd.Flags().StringVarP(
40-
&audioTrackType, "audioTrackType", "a", "unknown",
41-
"unknown, primary, commentary or descriptive",
42-
)
43-
insertCmd.Flags().BoolVarP(
44-
isAutoSynced, "isAutoSynced", "A", true,
45-
"Whether YouTube synchronized the caption track to the audio track in the video",
46-
)
47-
insertCmd.Flags().BoolVarP(
48-
isCC, "isCC", "C", false,
49-
"Whether the track contains closed captions for the deaf and hard of hearing",
44+
&audioTrackType, "audioTrackType", "a", "unknown", attUsage,
5045
)
5146
insertCmd.Flags().BoolVarP(
52-
isDraft, "isDraft", "D", false, "whether the caption track is a draft",
47+
isAutoSynced, "isAutoSynced", "A", true, iasUsage,
5348
)
49+
insertCmd.Flags().BoolVarP(isCC, "isCC", "C", false, iscUsage)
50+
insertCmd.Flags().BoolVarP(isDraft, "isDraft", "D", false, isdUsage)
5451
insertCmd.Flags().BoolVarP(
55-
isEasyReader, "isEasyReader", "E", false,
56-
"Whether caption track is formatted for 'easy reader'",
57-
)
58-
insertCmd.Flags().BoolVarP(
59-
isLarge, "isLarge", "L", false,
60-
"Whether the caption track uses large text for the vision-impaired",
61-
)
62-
insertCmd.Flags().StringVarP(
63-
&language, "language", "l", "", "Language of the caption track",
52+
isEasyReader, "isEasyReader", "E", false, iserUsage,
6453
)
54+
insertCmd.Flags().BoolVarP(isLarge, "isLarge", "L", false, islUsage)
55+
insertCmd.Flags().StringVarP(&language, "language", "l", "", languageUsage)
56+
insertCmd.Flags().StringVarP(&name, "name", "n", "", nameUsage)
6557
insertCmd.Flags().StringVarP(
66-
&name, "name", "n", "", "Name of the caption track",
58+
&trackKind, "trackKind", "t", "standard", tkUsage,
6759
)
68-
insertCmd.Flags().StringVarP(
69-
&trackKind, "trackKind", "t", "standard", "standard, ASR or forced",
70-
)
71-
insertCmd.Flags().StringVarP(&videoId, "videoId", "v", "", "ID of the video")
60+
insertCmd.Flags().StringVarP(&videoId, "videoId", "v", "", vidUsage)
7261
insertCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
7362
insertCmd.Flags().StringVarP(
7463
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "",
7564
)
76-
insertCmd.Flags().StringVarP(
77-
&output, "output", "o", "", "json, yaml or silent",
78-
)
65+
insertCmd.Flags().StringVarP(&output, "output", "o", "", insertOutputUsage)
7966
}

cmd/caption/list.go

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

8+
const (
9+
listOutputUsage = "json or yaml"
10+
)
11+
812
var listCmd = &cobra.Command{
913
Use: "list",
1014
Short: "List captions",
@@ -24,14 +28,14 @@ var listCmd = &cobra.Command{
2428
func init() {
2529
captionCmd.AddCommand(listCmd)
2630

27-
listCmd.Flags().StringVarP(&id, "id", "i", "", "ID of the caption")
28-
listCmd.Flags().StringVarP(&videoId, "videoId", "v", "", "ID of the video")
31+
listCmd.Flags().StringVarP(&id, "id", "i", "", idUsage)
32+
listCmd.Flags().StringVarP(&videoId, "videoId", "v", "", vidUsage)
2933
listCmd.Flags().StringVarP(&onBehalfOf, "onBehalfOf", "b", "", "")
3034
listCmd.Flags().StringVarP(
3135
&onBehalfOfContentOwner, "onBehalfOfContentOwner", "B", "", "",
3236
)
3337
listCmd.Flags().StringArrayVarP(
34-
&parts, "parts", "p", []string{"id", "snippet"}, "Comma separated parts",
38+
&parts, "parts", "p", []string{"id", "snippet"}, partsUsage,
3539
)
36-
listCmd.Flags().StringVarP(&output, "output", "o", "", "json or yaml")
40+
listCmd.Flags().StringVarP(&output, "output", "o", "", listOutputUsage)
3741
}

0 commit comments

Comments
 (0)