mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: read template tar from stdin if stdin is not a tty (#14643)
This commit is contained in:
+15
-8
@@ -51,7 +51,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
name, err := uploadFlags.templateName(inv.Args)
|
||||
name, err := uploadFlags.templateName(inv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -87,7 +87,7 @@ func (r *RootCmd) templatePush() *serpent.Command {
|
||||
message := uploadFlags.templateMessage(inv)
|
||||
|
||||
var varsFiles []string
|
||||
if !uploadFlags.stdin() {
|
||||
if !uploadFlags.stdin(inv) {
|
||||
varsFiles, err = codersdk.DiscoverVarsFiles(uploadFlags.directory)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -275,13 +275,19 @@ func (pf *templateUploadFlags) setWorkdir(wd string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (pf *templateUploadFlags) stdin() bool {
|
||||
return pf.directory == "-"
|
||||
func (pf *templateUploadFlags) stdin(inv *serpent.Invocation) (out bool) {
|
||||
defer func() {
|
||||
if out {
|
||||
inv.Logger.Info(inv.Context(), "uploading tar read from stdin")
|
||||
}
|
||||
}()
|
||||
// We let the directory override our isTTY check
|
||||
return pf.directory == "-" || (!isTTYIn(inv) && pf.directory == "")
|
||||
}
|
||||
|
||||
func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.Client) (*codersdk.UploadResponse, error) {
|
||||
var content io.Reader
|
||||
if pf.stdin() {
|
||||
if pf.stdin(inv) {
|
||||
content = inv.Stdin
|
||||
} else {
|
||||
prettyDir := prettyDirectoryPath(pf.directory)
|
||||
@@ -317,7 +323,7 @@ func (pf *templateUploadFlags) upload(inv *serpent.Invocation, client *codersdk.
|
||||
}
|
||||
|
||||
func (pf *templateUploadFlags) checkForLockfile(inv *serpent.Invocation) error {
|
||||
if pf.stdin() || pf.ignoreLockfile {
|
||||
if pf.stdin(inv) || pf.ignoreLockfile {
|
||||
// Just assume there's a lockfile if reading from stdin.
|
||||
return nil
|
||||
}
|
||||
@@ -350,8 +356,9 @@ func (pf *templateUploadFlags) templateMessage(inv *serpent.Invocation) string {
|
||||
return "Uploaded from the CLI"
|
||||
}
|
||||
|
||||
func (pf *templateUploadFlags) templateName(args []string) (string, error) {
|
||||
if pf.stdin() {
|
||||
func (pf *templateUploadFlags) templateName(inv *serpent.Invocation) (string, error) {
|
||||
args := inv.Args
|
||||
if pf.stdin(inv) {
|
||||
// Can't infer name from directory if none provided.
|
||||
if len(args) == 0 {
|
||||
return "", xerrors.New("template name argument must be provided")
|
||||
|
||||
Reference in New Issue
Block a user