Skip to content

Commit

Permalink
refactor: make raw abs path a getter
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 17, 2023
1 parent 931096e commit bc5d76d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type client struct {
apiPrefix string
headers map[string]string
fallback cmds.Executor
rawAbsPath bool
getRawAbsPath func() (bool, error)
}

// ClientOpt is an option that can be passed to the HTTP client constructor.
Expand Down Expand Up @@ -76,10 +76,11 @@ func ClientWithFallback(exe cmds.Executor) ClientOpt {
}
}

// ClientWithRawAbsPath enables the rawAbspath for [files.NewMultiFileReader].
func ClientWithRawAbsPath(rawAbsPath bool) ClientOpt {
// ClientWithRawAbsPath enables the rawAbspath for [files.NewMultiFileReader]
// given the result of the given function.
func ClientWithRawAbsPath(getRawAbsPath func() (bool, error)) ClientOpt {
return func(c *client) {
c.rawAbsPath = rawAbsPath
c.getRawAbsPath = getRawAbsPath
}

Check warning on line 84 in http/client.go

View check run for this annotation

Codecov / codecov/patch

http/client.go#L81-L84

Added lines #L81 - L84 were not covered by tests
}

Expand Down Expand Up @@ -164,15 +165,23 @@ func (c *client) toHTTPRequest(req *cmds.Request) (*http.Request, error) {
var reader io.Reader // in case we have no body to send we need to provide
// untyped nil to http.NewRequest

var rawAbsPath bool
if c.getRawAbsPath != nil {
rawAbsPath, err = c.getRawAbsPath()
if err != nil {
return nil, err
}

Check warning on line 173 in http/client.go

View check run for this annotation

Codecov / codecov/patch

http/client.go#L170-L173

Added lines #L170 - L173 were not covered by tests
}

if bodyArgs := req.BodyArgs(); bodyArgs != nil {
// In the end, this wraps a file reader in a file reader.
// However, such is life.
fileReader = files.NewMultiFileReader(files.NewMapDirectory(map[string]files.Node{
"stdin": files.NewReaderFile(bodyArgs),
}), true, c.rawAbsPath)
}), true, rawAbsPath)

Check warning on line 181 in http/client.go

View check run for this annotation

Codecov / codecov/patch

http/client.go#L181

Added line #L181 was not covered by tests
reader = fileReader
} else if req.Files != nil {
fileReader = files.NewMultiFileReader(req.Files, true, c.rawAbsPath)
fileReader = files.NewMultiFileReader(req.Files, true, rawAbsPath)
reader = fileReader
}

Expand Down

0 comments on commit bc5d76d

Please sign in to comment.