github.com/fastly/cli@v1.7.2-0.20240304164155-9d0f1d77c3bf/pkg/commands/compute/language_other.go (about)

     1  package compute
     2  
     3  import (
     4  	"io"
     5  
     6  	fsterr "github.com/fastly/cli/pkg/errors"
     7  	"github.com/fastly/cli/pkg/text"
     8  )
     9  
    10  // NewOther constructs a new unsupported language instance.
    11  func NewOther(
    12  	c *BuildCommand,
    13  	in io.Reader,
    14  	manifestFilename string,
    15  	out io.Writer,
    16  	spinner text.Spinner,
    17  ) *Other {
    18  	return &Other{
    19  		Shell: Shell{},
    20  
    21  		autoYes:               c.Globals.Flags.AutoYes,
    22  		build:                 c.Globals.Manifest.File.Scripts.Build,
    23  		defaultBuild:          false, // there is no default build for 'other'
    24  		env:                   c.Globals.Manifest.File.Scripts.EnvVars,
    25  		errlog:                c.Globals.ErrLog,
    26  		input:                 in,
    27  		manifestFilename:      manifestFilename,
    28  		metadataFilterEnvVars: c.MetadataFilterEnvVars,
    29  		nonInteractive:        c.Globals.Flags.NonInteractive,
    30  		output:                out,
    31  		postBuild:             c.Globals.Manifest.File.Scripts.PostBuild,
    32  		spinner:               spinner,
    33  		timeout:               c.Flags.Timeout,
    34  		verbose:               c.Globals.Verbose(),
    35  	}
    36  }
    37  
    38  // Other implements a Toolchain for languages without official support.
    39  type Other struct {
    40  	Shell
    41  
    42  	// autoYes is the --auto-yes flag.
    43  	autoYes bool
    44  	// build is a shell command defined in fastly.toml using [scripts.build].
    45  	build string
    46  	// defaultBuild indicates if the default build script was used.
    47  	defaultBuild bool
    48  	// env is environment variables to be set.
    49  	env []string
    50  	// errlog is an abstraction for recording errors to disk.
    51  	errlog fsterr.LogInterface
    52  	// input is the user's terminal stdin stream
    53  	input io.Reader
    54  	// manifestFilename is the name of the manifest file.
    55  	manifestFilename string
    56  	// metadataFilterEnvVars is a comma-separated list of user defined env vars.
    57  	metadataFilterEnvVars string
    58  	// nonInteractive is the --non-interactive flag.
    59  	nonInteractive bool
    60  	// output is the users terminal stdout stream
    61  	output io.Writer
    62  	// postBuild is a custom script executed after the build but before the Wasm
    63  	// binary is added to the .tar.gz archive.
    64  	postBuild string
    65  	// spinner is a terminal progress status indicator.
    66  	spinner text.Spinner
    67  	// timeout is the build execution threshold.
    68  	timeout int
    69  	// verbose indicates if the user set --verbose
    70  	verbose bool
    71  }
    72  
    73  // DefaultBuildScript indicates if a custom build script was used.
    74  func (o Other) DefaultBuildScript() bool {
    75  	return o.defaultBuild
    76  }
    77  
    78  // Dependencies returns all dependencies used by the project.
    79  func (o Other) Dependencies() map[string]string {
    80  	deps := make(map[string]string)
    81  	return deps
    82  }
    83  
    84  // Build implements the Toolchain interface and attempts to compile the package
    85  // source to a Wasm binary.
    86  func (o Other) Build() error {
    87  	bt := BuildToolchain{
    88  		autoYes:               o.autoYes,
    89  		buildFn:               o.Shell.Build,
    90  		buildScript:           o.build,
    91  		env:                   o.env,
    92  		errlog:                o.errlog,
    93  		in:                    o.input,
    94  		manifestFilename:      o.manifestFilename,
    95  		metadataFilterEnvVars: o.metadataFilterEnvVars,
    96  		nonInteractive:        o.nonInteractive,
    97  		out:                   o.output,
    98  		postBuild:             o.postBuild,
    99  		spinner:               o.spinner,
   100  		timeout:               o.timeout,
   101  		verbose:               o.verbose,
   102  	}
   103  	return bt.Build()
   104  }