From 0c6709938149ec2f409f9a181dc79f990d2b0c46 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 24 Jun 2018 21:12:53 -0300 Subject: [PATCH] feat: add args to snapcraft commands --- config/config.go | 1 + pipeline/snapcraft/snapcraft.go | 5 +++++ pipeline/snapcraft/snapcraft_test.go | 4 +++- www/content/linux-packages.md | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 9854f0b24..30c107a07 100644 --- a/config/config.go +++ b/config/config.go @@ -206,6 +206,7 @@ type Sign struct { type SnapcraftAppMetadata struct { Plugs []string Daemon string + Args string } // Snapcraft config diff --git a/pipeline/snapcraft/snapcraft.go b/pipeline/snapcraft/snapcraft.go index e9e25ebf6..01fc31ab5 100644 --- a/pipeline/snapcraft/snapcraft.go +++ b/pipeline/snapcraft/snapcraft.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/apex/log" "golang.org/x/sync/errgroup" @@ -153,6 +154,10 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err if configAppMetadata, ok := ctx.Config.Snapcraft.Apps[binary.Name]; ok { appMetadata.Plugs = configAppMetadata.Plugs appMetadata.Daemon = configAppMetadata.Daemon + appMetadata.Command = strings.Join([]string{ + appMetadata.Command, + configAppMetadata.Args, + }, " ") } metadata.Apps[binary.Name] = appMetadata diff --git a/pipeline/snapcraft/snapcraft_test.go b/pipeline/snapcraft/snapcraft_test.go index 39e33476a..68fe2f435 100644 --- a/pipeline/snapcraft/snapcraft_test.go +++ b/pipeline/snapcraft/snapcraft_test.go @@ -107,7 +107,7 @@ func TestRunPipeWithName(t *testing.T) { assert.Equal(t, metadata.Name, "testsnapname") } -func TestRunPipeWithPlugsAndDaemon(t *testing.T) { +func TestRunPipeMetadata(t *testing.T) { folder, err := ioutil.TempDir("", "archivetest") assert.NoError(t, err) var dist = filepath.Join(folder, "dist") @@ -124,6 +124,7 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) { "mybin": { Plugs: []string{"home", "network"}, Daemon: "simple", + Args: "--foo --bar", }, }, }, @@ -138,6 +139,7 @@ func TestRunPipeWithPlugsAndDaemon(t *testing.T) { assert.NoError(t, err) assert.Equal(t, metadata.Apps["mybin"].Plugs, []string{"home", "network"}) assert.Equal(t, metadata.Apps["mybin"].Daemon, "simple") + assert.Equal(t, metadata.Apps["mybin"].Command, "mybin --foo --bar") } func TestNoSnapcraftInPath(t *testing.T) { diff --git a/www/content/linux-packages.md b/www/content/linux-packages.md index eee596f1f..597bf9d2e 100644 --- a/www/content/linux-packages.md +++ b/www/content/linux-packages.md @@ -239,6 +239,10 @@ snapcraft: # If you want your app to be autostarted and to always run in the # background, you can make it a simple daemon. daemon: simple + + # If you any to pass args to your binary, you can add them with the + # args option. + args: --foo ``` Note that GoReleaser will not install `snapcraft` nor any of its dependencies