@@ -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,13 @@ 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 ) bool {
279
+ return pf .directory == "-" || ( ! isTTYIn ( inv ) && pf . directory == "" )
280
280
}
281
281
282
282
func (pf * templateUploadFlags ) upload (inv * serpent.Invocation , client * codersdk.Client ) (* codersdk.UploadResponse , error ) {
283
283
var content io.Reader
284
- if pf .stdin () {
284
+ if pf .stdin (inv ) {
285
285
content = inv .Stdin
286
286
} else {
287
287
prettyDir := prettyDirectoryPath (pf .directory )
@@ -317,7 +317,7 @@ func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.
317
317
}
318
318
319
319
func (pf * templateUploadFlags ) checkForLockfile (inv * serpent.Invocation ) error {
320
- if pf .stdin () || pf .ignoreLockfile {
320
+ if pf .stdin (inv ) || pf .ignoreLockfile {
321
321
// Just assume there's a lockfile if reading from stdin.
322
322
return nil
323
323
}
@@ -350,8 +350,9 @@ func (pf *templateUploadFlags) templateMessage(inv *serpent.Invocation) string {
350
350
return "Uploaded from the CLI"
351
351
}
352
352
353
- func (pf * templateUploadFlags ) templateName (args []string ) (string , error ) {
354
- if pf .stdin () {
353
+ func (pf * templateUploadFlags ) templateName (inv * serpent.Invocation ) (string , error ) {
354
+ args := inv .Args
355
+ if pf .stdin (inv ) {
355
356
// Can't infer name from directory if none provided.
356
357
if len (args ) == 0 {
357
358
return "" , xerrors .New ("template name argument must be provided" )
0 commit comments