@@ -51,7 +51,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
51
51
return err
52
52
}
53
53
54
- name , err := uploadFlags .templateName (inv . Args )
54
+ name , err := uploadFlags .templateName (inv )
55
55
if err != nil {
56
56
return err
57
57
}
@@ -87,7 +87,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
87
87
message := uploadFlags .templateMessage (inv )
88
88
89
89
var varsFiles []string
90
- if ! uploadFlags .stdin () {
90
+ if ! uploadFlags .stdin (inv ) {
91
91
varsFiles , err = codersdk .DiscoverVarsFiles (uploadFlags .directory )
92
92
if err != nil {
93
93
return err
@@ -275,13 +275,19 @@ func (pf *templateUploadFlags) setWorkdir(wd string) {
275
275
}
276
276
}
277
277
278
- func (pf * templateUploadFlags ) stdin () bool {
279
- return pf .directory == "-"
278
+ func (pf * templateUploadFlags ) stdin (inv * serpent.Invocation ) (out bool ) {
279
+ defer func () {
280
+ if out {
281
+ inv .Logger .Info (inv .Context (), "uploading tar read from stdin" )
282
+ }
283
+ }()
284
+ // We let the directory override our isTTY check
285
+ return pf .directory == "-" || (! isTTYIn (inv ) && pf .directory == "" )
280
286
}
281
287
282
288
func (pf * templateUploadFlags ) upload (inv * serpent.Invocation , client * codersdk.Client ) (* codersdk.UploadResponse , error ) {
283
289
var content io.Reader
284
- if pf .stdin () {
290
+ if pf .stdin (inv ) {
285
291
content = inv .Stdin
286
292
} else {
287
293
prettyDir := prettyDirectoryPath (pf .directory )
@@ -317,7 +323,7 @@ func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.
317
323
}
318
324
319
325
func (pf * templateUploadFlags ) checkForLockfile (inv * serpent.Invocation ) error {
320
- if pf .stdin () || pf .ignoreLockfile {
326
+ if pf .stdin (inv ) || pf .ignoreLockfile {
321
327
// Just assume there's a lockfile if reading from stdin.
322
328
return nil
323
329
}
@@ -350,8 +356,9 @@ func (pf *templateUploadFlags) templateMessage(inv *serpent.Invocation) string {
350
356
return "Uploaded from the CLI"
351
357
}
352
358
353
- func (pf * templateUploadFlags ) templateName (args []string ) (string , error ) {
354
- if pf .stdin () {
359
+ func (pf * templateUploadFlags ) templateName (inv * serpent.Invocation ) (string , error ) {
360
+ args := inv .Args
361
+ if pf .stdin (inv ) {
355
362
// Can't infer name from directory if none provided.
356
363
if len (args ) == 0 {
357
364
return "" , xerrors .New ("template name argument must be provided" )
0 commit comments