Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all 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
15 changes: 15 additions & 0 deletions sdk/provision/file_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/rand"
"fmt"
"path/filepath"
"text/template"

"github.com/1Password/shell-plugins/sdk"
Expand All @@ -18,6 +19,7 @@ type FileProvisioner struct {
outfileName string
outpathFixed string
outpathEnvVar string
outdirEnvVar string
setOutpathAsArg bool
outpathArgTemplates []string
}
Expand Down Expand Up @@ -74,6 +76,13 @@ func SetPathAsEnvVar(envVarName string) FileOption {
}
}

// SetOutputDirAsEnvVar can be used to provision the directory of the output file as an environment variable.
func SetOutputDirAsEnvVar(envVarName string) FileOption {
return func(p *FileProvisioner) {
p.outdirEnvVar = envVarName
}
}

// AddArgs can be used to add args to the command line. This is useful when the output file path
// should be passed as an arg. The output path is available as "{{ .Path }}" in each arg.
// For example:
Expand Down Expand Up @@ -118,6 +127,12 @@ func (p FileProvisioner) Provision(ctx context.Context, in sdk.ProvisionInput, o
out.AddEnvVar(p.outpathEnvVar, outpath)
}

if p.outdirEnvVar != "" {
// Populate the specified environment variable with the output dir.
dir := filepath.Dir(outpath)
out.AddEnvVar(p.outpathEnvVar, dir)
}

// Add args to specify the output path.
if p.setOutpathAsArg {
tmplData := struct{ Path string }{
Expand Down