{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/65356690","id":65356690,"diff_hunk":"@@ -0,0 +1,146 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2014-2016 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+package main\n+\n+import (\n+\t\"fmt\"\n+\t\"os\"\n+\t\"syscall\"\n+\n+\t\"github.com/jessevdk/go-flags\"\n+\n+\t\"github.com/snapcore/snapd/arch\"\n+\t\"github.com/snapcore/snapd/i18n\"\n+\t\"github.com/snapcore/snapd/snap\"\n+\t\"github.com/snapcore/snapd/snap/snapenv\"\n+)\n+\n+type cmdRun struct {\n+\tPositional struct {\n+\t\tSnapApp string `positional-arg-name:\"<snapApp>\" description:\"the application to run, e.g. hello-world.env\"`\n+\t} `positional-args:\"yes\" required:\"yes\"`\n+\n+\tCommand string `long:\"command\" description:\"use a different command like {stop,post-stop} from the app\"`\n+}\n+\n+func init() {\n+\taddCommand(\"run\",\n+\t\ti18n.G(\"Run the given snap command\"),\n+\t\ti18n.G(\"Run the given snap command with the right confinement and environment\"),\n+\t\tfunc() flags.Commander {\n+\t\t\treturn &cmdRun{}\n+\t\t})\n+}\n+\n+func (x *cmdRun) Execute(args []string) error {\n+\treturn snapRun(x.Positional.SnapApp, x.Command, args)\n+}\n+\n+func getSnapInfo(snapName string) (*snap.Info, error) {\n+\t// we need to get the revision here because once we are inside\n+\t// the confinement its not available anymore\n+\tsnaps, err := Client().List([]string{snapName})\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif len(snaps) == 0 {\n+\t\treturn nil, fmt.Errorf(\"cannot find snap %q\", snapName)\n+\t}\n+\tif len(snaps) > 1 {\n+\t\treturn nil, fmt.Errorf(\"multiple snaps for %q: %d\", snapName, len(snaps))\n+\t}\n+\tsn := snaps[0]\n+\tinfo, err := snap.ReadInfo(snapName, &snap.SideInfo{\n+\t\tRevision: snap.R(sn.Revision.N),\n+\t})\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\treturn info, nil\n+}\n+\n+// returns phase1 env (same vars for all apps)\n+func getPhase1AppEnv(app *snap.AppInfo) []string {\n+\tenv := []string{}\n+\twrapperData := struct {\n+\t\tApp     *snap.AppInfo\n+\t\tEnvVars string\n+\t\t// XXX: needed by snapenv\n+\t\tSnapName string\n+\t\tSnapArch string\n+\t\tSnapPath string\n+\t\tVersion  string\n+\t\tRevision snap.Revision\n+\t\tHome     string\n+\t}{\n+\t\tApp: app,\n+\t\t// XXX: needed by snapenv\n+\t\tSnapName: app.Snap.Name(),\n+\t\tSnapArch: arch.UbuntuArchitecture(),\n+\t\tSnapPath: app.Snap.MountDir(),\n+\t\tVersion:  app.Snap.Version,\n+\t\tRevision: app.Snap.Revision,\n+\t\t// must be an absolute path for\n+\t\t//   ubuntu-core-launcher/snap-confine\n+\t\t// which will mkdir() SNAP_USER_DATA for us\n+\t\tHome: os.Getenv(\"$HOME\"),\n+\t}\n+\tfor _, envVar := range append(\n+\t\tsnapenv.GetBasicSnapEnvVars(wrapperData),\n+\t\tsnapenv.GetUserSnapEnvVars(wrapperData)...) {","path":"cmd/snap/cmd_run.go","position":108,"original_position":108,"commit_id":"fc2a27dce0032fafbf9ed8998bbffdbf671f1c8c","original_commit_id":"fc2a27dce0032fafbf9ed8998bbffdbf671f1c8c","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"body":"yes, it's still doing awkward things, is not quite one of my cleanup targets atm though","created_at":"2016-06-01T13:12:14Z","updated_at":"2016-06-01T13:12:14Z","html_url":"https://github.com/snapcore/snapd/pull/1247#discussion_r65356690","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/1247","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/65356690"},"html":{"href":"https://github.com/snapcore/snapd/pull/1247#discussion_r65356690"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1247"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/1247","id":71986427,"html_url":"https://github.com/snapcore/snapd/pull/1247","diff_url":"https://github.com/snapcore/snapd/pull/1247.diff","patch_url":"https://github.com/snapcore/snapd/pull/1247.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/1247","number":1247,"state":"open","locked":false,"title":"many: add new `snap run` command","user":{"login":"mvo5","id":914418,"avatar_url":"https://avatars.githubusercontent.com/u/914418?v=3","gravatar_id":"","url":"https://api.github.com/users/mvo5","html_url":"https://github.com/mvo5","followers_url":"https://api.github.com/users/mvo5/followers","following_url":"https://api.github.com/users/mvo5/following{/other_user}","gists_url":"https://api.github.com/users/mvo5/gists{/gist_id}","starred_url":"https://api.github.com/users/mvo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvo5/subscriptions","organizations_url":"https://api.github.com/users/mvo5/orgs","repos_url":"https://api.github.com/users/mvo5/repos","events_url":"https://api.github.com/users/mvo5/events{/privacy}","received_events_url":"https://api.github.com/users/mvo5/received_events","type":"User","site_admin":false},"body":"This branch is based on https://github.com/snapcore/snapd/pull/1246\r\n\r\nIt implements the new `snap run` command that allows to run apps from inside snaps via `snap run snapname.appname` or `snap run snapname` or `snap run snapname.appname --command={stop,post-stop}`. We will use this later in the service wrappers.","created_at":"2016-05-31T09:45:36Z","updated_at":"2016-06-01T13:12:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"456eb2e82c491d7a4eeb23e48429590e49a1df39","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/1247/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/1247/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/1247/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/fc2a27dce0032fafbf9ed8998bbffdbf671f1c8c","head":{"label":"mvo5:feature/snap-run2","ref":"feature/snap-run2","sha":"fc2a27dce0032fafbf9ed8998bbffdbf671f1c8c","user":{"login":"mvo5","id":914418,"avatar_url":"https://avatars.githubusercontent.com/u/914418?v=3","gravatar_id":"","url":"https://api.github.com/users/mvo5","html_url":"https://github.com/mvo5","followers_url":"https://api.github.com/users/mvo5/followers","following_url":"https://api.github.com/users/mvo5/following{/other_user}","gists_url":"https://api.github.com/users/mvo5/gists{/gist_id}","starred_url":"https://api.github.com/users/mvo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvo5/subscriptions","organizations_url":"https://api.github.com/users/mvo5/orgs","repos_url":"https://api.github.com/users/mvo5/repos","events_url":"https://api.github.com/users/mvo5/events{/privacy}","received_events_url":"https://api.github.com/users/mvo5/received_events","type":"User","site_admin":false},"repo":{"id":45067233,"name":"snappy","full_name":"mvo5/snappy","owner":{"login":"mvo5","id":914418,"avatar_url":"https://avatars.githubusercontent.com/u/914418?v=3","gravatar_id":"","url":"https://api.github.com/users/mvo5","html_url":"https://github.com/mvo5","followers_url":"https://api.github.com/users/mvo5/followers","following_url":"https://api.github.com/users/mvo5/following{/other_user}","gists_url":"https://api.github.com/users/mvo5/gists{/gist_id}","starred_url":"https://api.github.com/users/mvo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvo5/subscriptions","organizations_url":"https://api.github.com/users/mvo5/orgs","repos_url":"https://api.github.com/users/mvo5/repos","events_url":"https://api.github.com/users/mvo5/events{/privacy}","received_events_url":"https://api.github.com/users/mvo5/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mvo5/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/mvo5/snappy","forks_url":"https://api.github.com/repos/mvo5/snappy/forks","keys_url":"https://api.github.com/repos/mvo5/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mvo5/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mvo5/snappy/teams","hooks_url":"https://api.github.com/repos/mvo5/snappy/hooks","issue_events_url":"https://api.github.com/repos/mvo5/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/mvo5/snappy/events","assignees_url":"https://api.github.com/repos/mvo5/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/mvo5/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/mvo5/snappy/tags","blobs_url":"https://api.github.com/repos/mvo5/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mvo5/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mvo5/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/mvo5/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mvo5/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/mvo5/snappy/languages","stargazers_url":"https://api.github.com/repos/mvo5/snappy/stargazers","contributors_url":"https://api.github.com/repos/mvo5/snappy/contributors","subscribers_url":"https://api.github.com/repos/mvo5/snappy/subscribers","subscription_url":"https://api.github.com/repos/mvo5/snappy/subscription","commits_url":"https://api.github.com/repos/mvo5/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/mvo5/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/mvo5/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/mvo5/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/mvo5/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/mvo5/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mvo5/snappy/merges","archive_url":"https://api.github.com/repos/mvo5/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mvo5/snappy/downloads","issues_url":"https://api.github.com/repos/mvo5/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/mvo5/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/mvo5/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/mvo5/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mvo5/snappy/labels{/name}","releases_url":"https://api.github.com/repos/mvo5/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/mvo5/snappy/deployments","created_at":"2015-10-27T20:12:18Z","updated_at":"2016-01-11T10:04:34Z","pushed_at":"2016-06-01T13:07:08Z","git_url":"git://github.com/mvo5/snappy.git","ssh_url":"git@github.com:mvo5/snappy.git","clone_url":"https://github.com/mvo5/snappy.git","svn_url":"https://github.com/mvo5/snappy","homepage":null,"size":31288,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"c26c5552e388dccd898e3be3ce4c4f5bd39bc4af","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snapd","full_name":"snapcore/snapd","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":false,"url":"https://api.github.com/repos/snapcore/snapd","forks_url":"https://api.github.com/repos/snapcore/snapd/forks","keys_url":"https://api.github.com/repos/snapcore/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapd/teams","hooks_url":"https://api.github.com/repos/snapcore/snapd/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapd/events","assignees_url":"https://api.github.com/repos/snapcore/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapd/tags","blobs_url":"https://api.github.com/repos/snapcore/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapd/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapd/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapd/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapd/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapd/subscription","commits_url":"https://api.github.com/repos/snapcore/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapd/merges","archive_url":"https://api.github.com/repos/snapcore/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapd/downloads","issues_url":"https://api.github.com/repos/snapcore/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapd/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapd/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2016-06-01T00:04:47Z","pushed_at":"2016-06-01T12:35:11Z","git_url":"git://github.com/snapcore/snapd.git","ssh_url":"git@github.com:snapcore/snapd.git","clone_url":"https://github.com/snapcore/snapd.git","svn_url":"https://github.com/snapcore/snapd","homepage":"","size":31829,"stargazers_count":202,"watchers_count":202,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":17,"forks":52,"open_issues":17,"watchers":202,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1247"},"html":{"href":"https://github.com/snapcore/snapd/pull/1247"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/1247"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/1247/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1247/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1247/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/fc2a27dce0032fafbf9ed8998bbffdbf671f1c8c"}}}}
{"actor":{"display_login":"pedronis"}}