get.porter.sh/porter@v1.3.0/pkg/pkgmgmt/pkgmgmt.go (about)

     1  package pkgmgmt
     2  
     3  import (
     4  	"context"
     5  	"net/url"
     6  	"os/exec"
     7  	"path"
     8  
     9  	"get.porter.sh/porter/pkg/portercontext"
    10  )
    11  
    12  // PackageManager handles searching, installing and communicating with packages.
    13  type PackageManager interface {
    14  	List() ([]string, error)
    15  	GetPackageDir(name string) (string, error)
    16  	GetMetadata(ctx context.Context, name string) (PackageMetadata, error)
    17  	Install(ctx context.Context, opts InstallOptions) error
    18  	Uninstall(ctx context.Context, opts UninstallOptions) error
    19  
    20  	// Run a command against the installed package.
    21  	Run(ctx context.Context, pkgContext *portercontext.Context, name string, commandOpts CommandOptions) error
    22  }
    23  
    24  type PreRunHandler func(command string, cmd *exec.Cmd)
    25  
    26  // CommandOptions is data necessary to execute a command against a package (mixin or plugin).
    27  type CommandOptions struct {
    28  	// Runtime specifies if the client or runtime executable should be targeted.
    29  	Runtime bool
    30  
    31  	// Command to pass to the package.
    32  	Command string
    33  
    34  	// Input to pipe to stdin.
    35  	Input string
    36  
    37  	// File argument to specify as --file.
    38  	File string
    39  
    40  	// PreRun allows the caller to tweak the command before it is executed.
    41  	// This is only necessary if being called directly from a runner, if
    42  	// using a PackageManager, this is set for you.
    43  	PreRun PreRunHandler
    44  }
    45  
    46  // GetPackageListURL returns the URL for package listings of the provided type.
    47  func GetPackageListURL(mirror url.URL, pkgType string) string {
    48  	mirror.Path = path.Join(mirror.Path, pkgType+"s", "index.json")
    49  	return mirror.String()
    50  }