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

Commitefd532e

Browse files
chore: read template tar from stdin if stdin is not a tty (#14643)
1 parentd6154c4 commitefd532e

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

‎cli/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (r *RootCmd) login() *serpent.Command {
212212
_,_=fmt.Fprintf(inv.Stdout,Caret+"Your Coder deployment hasn't been set up!\n")
213213

214214
ifusername=="" {
215-
if!isTTY(inv) {
215+
if!isTTYIn(inv) {
216216
returnxerrors.New("the initial user cannot be created in non-interactive mode. use the API")
217217
}
218218

‎cli/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ func (r *RootCmd) createConfig() config.Root {
692692
returnconfig.Root(r.globalConfig)
693693
}
694694

695-
//isTTY returns whether the passedreader isa TTY or not.
696-
funcisTTY(inv*serpent.Invocation)bool {
695+
//isTTYIn returns whether the passedinvocation ishaving stdin read from a TTY
696+
funcisTTYIn(inv*serpent.Invocation)bool {
697697
// If the `--force-tty` command is available, and set,
698698
// assume we're in a tty. This is primarily for cases on Windows
699699
// where we may not be able to reliably detect this automatically (ie, tests)
@@ -708,12 +708,12 @@ func isTTY(inv *serpent.Invocation) bool {
708708
returnisatty.IsTerminal(file.Fd())
709709
}
710710

711-
// isTTYOut returns whether the passedreader isa TTY or not.
711+
// isTTYOut returns whether the passedinvocation ishaving stdout written to a TTY
712712
funcisTTYOut(inv*serpent.Invocation)bool {
713713
returnisTTYWriter(inv,inv.Stdout)
714714
}
715715

716-
// isTTYErr returns whether the passedreader isa TTY or not.
716+
// isTTYErr returns whether the passedinvocation ishaving stderr written to a TTY
717717
funcisTTYErr(inv*serpent.Invocation)bool {
718718
returnisTTYWriter(inv,inv.Stderr)
719719
}

‎cli/templatecreate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
7474
returnerr
7575
}
7676

77-
templateName,err:=uploadFlags.templateName(inv.Args)
77+
templateName,err:=uploadFlags.templateName(inv)
7878
iferr!=nil {
7979
returnerr
8080
}
@@ -96,7 +96,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
9696
message:=uploadFlags.templateMessage(inv)
9797

9898
varvarsFiles []string
99-
if!uploadFlags.stdin() {
99+
if!uploadFlags.stdin(inv) {
100100
varsFiles,err=codersdk.DiscoverVarsFiles(uploadFlags.directory)
101101
iferr!=nil {
102102
returnerr
@@ -139,7 +139,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
139139
returnerr
140140
}
141141

142-
if!uploadFlags.stdin() {
142+
if!uploadFlags.stdin(inv) {
143143
_,err=cliui.Prompt(inv, cliui.PromptOptions{
144144
Text:"Confirm create?",
145145
IsConfirm:true,

‎cli/templatepush.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
5151
returnerr
5252
}
5353

54-
name,err:=uploadFlags.templateName(inv.Args)
54+
name,err:=uploadFlags.templateName(inv)
5555
iferr!=nil {
5656
returnerr
5757
}
@@ -87,7 +87,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
8787
message:=uploadFlags.templateMessage(inv)
8888

8989
varvarsFiles []string
90-
if!uploadFlags.stdin() {
90+
if!uploadFlags.stdin(inv) {
9191
varsFiles,err=codersdk.DiscoverVarsFiles(uploadFlags.directory)
9292
iferr!=nil {
9393
returnerr
@@ -275,13 +275,19 @@ func (pf *templateUploadFlags) setWorkdir(wd string) {
275275
}
276276
}
277277

278-
func (pf*templateUploadFlags)stdin()bool {
279-
returnpf.directory=="-"
278+
func (pf*templateUploadFlags)stdin(inv*serpent.Invocation) (outbool) {
279+
deferfunc() {
280+
ifout {
281+
inv.Logger.Info(inv.Context(),"uploading tar read from stdin")
282+
}
283+
}()
284+
// We let the directory override our isTTY check
285+
returnpf.directory=="-"|| (!isTTYIn(inv)&&pf.directory=="")
280286
}
281287

282288
func (pf*templateUploadFlags)upload(inv*serpent.Invocation,client*codersdk.Client) (*codersdk.UploadResponse,error) {
283289
varcontent io.Reader
284-
ifpf.stdin() {
290+
ifpf.stdin(inv) {
285291
content=inv.Stdin
286292
}else {
287293
prettyDir:=prettyDirectoryPath(pf.directory)
@@ -317,7 +323,7 @@ func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.
317323
}
318324

319325
func (pf*templateUploadFlags)checkForLockfile(inv*serpent.Invocation)error {
320-
ifpf.stdin()||pf.ignoreLockfile {
326+
ifpf.stdin(inv)||pf.ignoreLockfile {
321327
// Just assume there's a lockfile if reading from stdin.
322328
returnnil
323329
}
@@ -350,8 +356,9 @@ func (pf *templateUploadFlags) templateMessage(inv *serpent.Invocation) string {
350356
return"Uploaded from the CLI"
351357
}
352358

353-
func (pf*templateUploadFlags)templateName(args []string) (string,error) {
354-
ifpf.stdin() {
359+
func (pf*templateUploadFlags)templateName(inv*serpent.Invocation) (string,error) {
360+
args:=inv.Args
361+
ifpf.stdin(inv) {
355362
// Can't infer name from directory if none provided.
356363
iflen(args)==0 {
357364
return"",xerrors.New("template name argument must be provided")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp