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

chore: read template tar from stdin if stdin is not a tty#14643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletioncli/login.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -212,7 +212,7 @@ func (r *RootCmd) login() *serpent.Command {
_, _ = fmt.Fprintf(inv.Stdout, Caret+"Your Coder deployment hasn't been set up!\n")

if username == "" {
if !isTTY(inv) {
if !isTTYIn(inv) {
return xerrors.New("the initial user cannot be created in non-interactive mode. use the API")
}

Expand Down
8 changes: 4 additions & 4 deletionscli/root.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -692,8 +692,8 @@ func (r *RootCmd) createConfig() config.Root {
returnconfig.Root(r.globalConfig)
}

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

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

// isTTYErr returns whether the passedreader isa TTY or not.
// isTTYErr returns whether the passedinvocation ishaving stderr written to a TTY
funcisTTYErr(inv*serpent.Invocation)bool {
returnisTTYWriter(inv,inv.Stderr)
}
Expand Down
6 changes: 3 additions & 3 deletionscli/templatecreate.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,7 +74,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
return err
}

templateName, err := uploadFlags.templateName(inv.Args)
templateName, err := uploadFlags.templateName(inv)
if err != nil {
return err
}
Expand All@@ -96,7 +96,7 @@ func (r *RootCmd) templateCreate() *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
Expand DownExpand Up@@ -139,7 +139,7 @@ func (r *RootCmd) templateCreate() *serpent.Command {
return err
}

if !uploadFlags.stdin() {
if !uploadFlags.stdin(inv) {
_, err = cliui.Prompt(inv, cliui.PromptOptions{
Text: "Confirm create?",
IsConfirm: true,
Expand Down
23 changes: 15 additions & 8 deletionscli/templatepush.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
}
Expand DownExpand Up@@ -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
Expand DownExpand Up@@ -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)
Expand DownExpand Up@@ -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
}
Expand DownExpand Up@@ -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")
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp