Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4869325

Browse files
committed
chore(cli): use option source name for deprecation warnings
1 parentc3c23ed commit4869325

File tree

7 files changed

+55
-35
lines changed

7 files changed

+55
-35
lines changed

‎cli/restart.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (r *RootCmd) restart() *serpent.Command {
2626
Short:"Restart a workspace",
2727
Middleware:serpent.Chain(
2828
serpent.RequireNArgs(1),
29+
PrintDeprecatedOptions(),
2930
r.InitClient(client),
3031
),
3132
Options: serpent.OptionSet{cliui.SkipPromptOption()},

‎cli/root.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,3 +1307,53 @@ func headerTransport(ctx context.Context, serverURL *url.URL, header []string, h
13071307
}
13081308
returntransport,nil
13091309
}
1310+
1311+
// printDeprecatedOptions loops through all command options, and prints
1312+
// a warning for usage of deprecated options.
1313+
funcPrintDeprecatedOptions() serpent.MiddlewareFunc {
1314+
returnfunc(next serpent.HandlerFunc) serpent.HandlerFunc {
1315+
returnfunc(inv*serpent.Invocation)error {
1316+
opts:=inv.Command.Options
1317+
// Print deprecation warnings.
1318+
for_,opt:=rangeopts {
1319+
ifopt.UseInstead==nil {
1320+
continue
1321+
}
1322+
1323+
ifopt.ValueSource==serpent.ValueSourceNone||opt.ValueSource==serpent.ValueSourceDefault {
1324+
continue
1325+
}
1326+
1327+
warnStr:=translateSource(opt.ValueSource,opt)+" is deprecated, please use "
1328+
fori,use:=rangeopt.UseInstead {
1329+
warnStr+=translateSource(opt.ValueSource,use)+" "
1330+
ifi!=len(opt.UseInstead)-1 {
1331+
warnStr+="and "
1332+
}
1333+
}
1334+
warnStr+="instead.\n"
1335+
1336+
cliui.Warn(inv.Stderr,
1337+
warnStr,
1338+
)
1339+
}
1340+
1341+
returnnext(inv)
1342+
}
1343+
}
1344+
}
1345+
1346+
// translateSource provides the name of the source of the option, depending on the
1347+
// supplied target ValueSource.
1348+
functranslateSource(target serpent.ValueSource,opt serpent.Option)string {
1349+
switchtarget {
1350+
caseserpent.ValueSourceFlag:
1351+
returnfmt.Sprintf("`--%s`",opt.Flag)
1352+
caseserpent.ValueSourceEnv:
1353+
returnfmt.Sprintf("`%s`",opt.Env)
1354+
caseserpent.ValueSourceYAML:
1355+
returnfmt.Sprintf("`%s`",opt.YAML)
1356+
default:
1357+
returnopt.Name
1358+
}
1359+
}

‎cli/server.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,41 +1240,6 @@ func templateHelpers(options *coderd.Options) map[string]any {
12401240
}
12411241
}
12421242

1243-
// printDeprecatedOptions loops through all command options, and prints
1244-
// a warning for usage of deprecated options.
1245-
funcPrintDeprecatedOptions() serpent.MiddlewareFunc {
1246-
returnfunc(next serpent.HandlerFunc) serpent.HandlerFunc {
1247-
returnfunc(inv*serpent.Invocation)error {
1248-
opts:=inv.Command.Options
1249-
// Print deprecation warnings.
1250-
for_,opt:=rangeopts {
1251-
ifopt.UseInstead==nil {
1252-
continue
1253-
}
1254-
1255-
ifopt.ValueSource==serpent.ValueSourceNone||opt.ValueSource==serpent.ValueSourceDefault {
1256-
continue
1257-
}
1258-
1259-
warnStr:=opt.Name+" is deprecated, please use "
1260-
fori,use:=rangeopt.UseInstead {
1261-
warnStr+=use.Name+" "
1262-
ifi!=len(opt.UseInstead)-1 {
1263-
warnStr+="and "
1264-
}
1265-
}
1266-
warnStr+="instead.\n"
1267-
1268-
cliui.Warn(inv.Stderr,
1269-
warnStr,
1270-
)
1271-
}
1272-
1273-
returnnext(inv)
1274-
}
1275-
}
1276-
}
1277-
12781243
// writeConfigMW will prevent the main command from running if the write-config
12791244
// flag is set. Instead, it will marshal the command options to YAML and write
12801245
// them to stdout.

‎cli/ssh.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (r *RootCmd) ssh() *serpent.Command {
7777
Middleware:serpent.Chain(
7878
serpent.RequireNArgs(1),
7979
r.InitClient(client),
80+
PrintDeprecatedOptions(),
8081
initAppearance(client,&appearanceConfig),
8182
),
8283
Handler:func(inv*serpent.Invocation) (retErrerror) {

‎cli/start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (r *RootCmd) start() *serpent.Command {
2525
Short:"Start a workspace",
2626
Middleware:serpent.Chain(
2727
serpent.RequireNArgs(1),
28+
PrintDeprecatedOptions(),
2829
r.InitClient(client),
2930
),
3031
Options: serpent.OptionSet{cliui.SkipPromptOption()},

‎cli/update.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func (r *RootCmd) update() *serpent.Command {
2222
Long:"Use --always-prompt to change the parameter values of the workspace.",
2323
Middleware:serpent.Chain(
2424
serpent.RequireNArgs(1),
25+
PrintDeprecatedOptions(),
2526
r.InitClient(client),
2627
),
2728
Handler:func(inv*serpent.Invocation)error {

‎enterprise/cli/provisionerdaemonstart.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func (r *RootCmd) provisionerDaemonStart() *serpent.Command {
5858
Use:"start",
5959
Short:"Run a provisioner daemon",
6060
Middleware:serpent.Chain(
61+
agpl.PrintDeprecatedOptions(),
6162
// disable checks and warnings because this command starts a daemon; it is
6263
// not meant for humans typing commands. Furthermore, the checks are
6364
// incompatible with PSK auth that this command uses

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp