{"action":"created","comment":{"url":"https://api.github.com/repos/opencontainers/runc/pulls/comments/53420588","id":53420588,"diff_hunk":"@@ -33,66 +46,77 @@ in json format:\n \t\t},\n \t},\n \tAction: func(context *cli.Context) {\n-\t\tformat := context.String(\"format\")\n-\t\tif format != \"\" {\n-\t\t\tswitch format {\n-\t\t\tdefault:\n-\t\t\t\tlogrus.Fatal(\"invalid format, valid formats are: \" + formatOptions)\n-\t\t\tcase \"\":\n-\t\t\t\tformat = \"table\"\n-\t\t\tcase \"json\", \"yaml\", \"xml\":\n-\t\t\t}\n-\t\t}\n-\t\t//quiet := context.Bool(\"quiet\")\n-\t\t//noTrunc := context.Bool(\"no-trunc\")\n-\n-\t\tfactory, err := loadFactory(context)\n-\t\tif err != nil {\n-\t\t\tlogrus.Fatal(err)\n-\t\t}\n-\t\t// get the list of containers\n-\t\troot := context.GlobalString(\"root\")\n-\t\tabsRoot, err := filepath.Abs(root)\n-\t\tif err != nil {\n-\t\t\tlogrus.Fatal(err)\n-\t\t}\n-\t\tlist, err := ioutil.ReadDir(absRoot)\n+\t\ts, err := getContainerList(context)\n \t\tif err != nil {\n \t\t\tlogrus.Fatal(err)\n \t\t}\n-\t\tw := tabwriter.NewWriter(os.Stdout, 12, 1, 3, ' ', 0)\n-\t\tfmt.Fprint(w, \"ID\\tPID\\tSTATUS\\tCREATED\\n\")\n-\t\t// output containers\n-\t\tfor _, item := range list {\n-\t\t\tif item.IsDir() {\n-\t\t\t\tif err := outputListInfo(item.Name(), factory, w); err != nil {\n-\t\t\t\t\tlogrus.Fatal(err)\n-\t\t\t\t}\n+\n+\t\tswitch context.String(\"format\") {\n+\t\tcase \"\", \"table\":\n+\t\t\tw := tabwriter.NewWriter(os.Stdout, 12, 1, 3, ' ', 0)\n+\t\t\tfmt.Fprint(w, \"ID\\tPID\\tSTATUS\\tCREATED\\n\")\n+\t\t\tfor _, item := range s.ContainerStates {\n+\t\t\t\tfmt.Fprintf(w, \"%s\\t%d\\t%s\\t%s\\n\",\n+\t\t\t\t\titem.BaseState.ID,\n+\t\t\t\t\titem.BaseState.InitProcessPid,\n+\t\t\t\t\titem.Status,\n+\t\t\t\t\titem.BaseState.Created.Format(time.RFC3339Nano))\n \t\t\t}\n-\t\t}\n-\t\tif err := w.Flush(); err != nil {\n-\t\t\tlogrus.Fatal(err)\n+\t\t\tif err := w.Flush(); err != nil {\n+\t\t\t\tlogrus.Fatal(err)\n+\t\t\t}\n+\t\tcase \"json\":\n+\t\t\tdata, err := json.MarshalIndent(s, \"\", \"\\t\")\n+\t\t\tif err != nil {\n+\t\t\t\tlogrus.Fatal(err)\n+\t\t\t}\n+\t\t\tos.Stdout.Write(data)\n+\t\t\tos.Stdout.WriteString(\"\\n\")\n+\n+\t\tdefault:\n+\t\t\tlogrus.Fatal(\"invalid format option\")\n \t\t}\n \t},\n }\n \n-func outputListInfo(id string, factory libcontainer.Factory, w *tabwriter.Writer) error {\n-\tcontainer, err := factory.Load(id)\n+func getContainerList(context *cli.Context) (*containerList, error) {\n+\tfactory, err := loadFactory(context)\n \tif err != nil {\n-\t\treturn err\n+\t\treturn nil, err\n \t}\n-\tcontainerStatus, err := container.Status()\n+\n+\t// get the list of containers\n+\troot := context.GlobalString(\"root\")\n+\tabsRoot, err := filepath.Abs(root)\n \tif err != nil {\n-\t\treturn err\n+\t\treturn nil, err\n \t}\n-\tstate, err := container.State()\n+\tlist, err := ioutil.ReadDir(absRoot)\n \tif err != nil {\n-\t\treturn err\n+\t\tlogrus.Fatal(err)\n+\t}\n+\n+\tvar countOfContainers = 0\n+\ts := &containerList{ContainerStates: make([]*containerState, len(list))}","path":"list.go","position":null,"original_position":124,"commit_id":"6aeedac655c11255c697008317bd0196fb03dc79","original_commit_id":"6866619b62ae3dca42b7016ff420a9783e5c195e","user":{"login":"mikebrow","id":12767641,"avatar_url":"https://avatars.githubusercontent.com/u/12767641?v=3","gravatar_id":"","url":"https://api.github.com/users/mikebrow","html_url":"https://github.com/mikebrow","followers_url":"https://api.github.com/users/mikebrow/followers","following_url":"https://api.github.com/users/mikebrow/following{/other_user}","gists_url":"https://api.github.com/users/mikebrow/gists{/gist_id}","starred_url":"https://api.github.com/users/mikebrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikebrow/subscriptions","organizations_url":"https://api.github.com/users/mikebrow/orgs","repos_url":"https://api.github.com/users/mikebrow/repos","events_url":"https://api.github.com/users/mikebrow/events{/privacy}","received_events_url":"https://api.github.com/users/mikebrow/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-02-19T04:02:22Z","updated_at":"2016-02-19T04:02:22Z","html_url":"https://github.com/opencontainers/runc/pull/571#discussion_r53420588","pull_request_url":"https://api.github.com/repos/opencontainers/runc/pulls/571","_links":{"self":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/comments/53420588"},"html":{"href":"https://github.com/opencontainers/runc/pull/571#discussion_r53420588"},"pull_request":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/571"}}},"pull_request":{"url":"https://api.github.com/repos/opencontainers/runc/pulls/571","id":59764222,"html_url":"https://github.com/opencontainers/runc/pull/571","diff_url":"https://github.com/opencontainers/runc/pull/571.diff","patch_url":"https://github.com/opencontainers/runc/pull/571.patch","issue_url":"https://api.github.com/repos/opencontainers/runc/issues/571","number":571,"state":"open","locked":false,"title":"adding --format json to list command","user":{"login":"mikebrow","id":12767641,"avatar_url":"https://avatars.githubusercontent.com/u/12767641?v=3","gravatar_id":"","url":"https://api.github.com/users/mikebrow","html_url":"https://github.com/mikebrow","followers_url":"https://api.github.com/users/mikebrow/followers","following_url":"https://api.github.com/users/mikebrow/following{/other_user}","gists_url":"https://api.github.com/users/mikebrow/gists{/gist_id}","starred_url":"https://api.github.com/users/mikebrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikebrow/subscriptions","organizations_url":"https://api.github.com/users/mikebrow/orgs","repos_url":"https://api.github.com/users/mikebrow/repos","events_url":"https://api.github.com/users/mikebrow/events{/privacy}","received_events_url":"https://api.github.com/users/mikebrow/received_events","type":"User","site_admin":false},"body":"Addresses issue #547.  Adds a json option to the list command.\r\n\r\nSigned-off-by: Mike Brown <brownwm@us.ibm.com>","created_at":"2016-02-18T08:15:09Z","updated_at":"2016-02-19T04:02:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dfe972b72f885ba7800f95b041e669d20c16aa79","assignee":null,"milestone":{"url":"https://api.github.com/repos/opencontainers/runc/milestones/2","html_url":"https://github.com/opencontainers/runc/milestones/0.0.9","labels_url":"https://api.github.com/repos/opencontainers/runc/milestones/2/labels","id":1564740,"number":2,"title":"0.0.9","description":"","creator":{"login":"crosbymichael","id":749551,"avatar_url":"https://avatars.githubusercontent.com/u/749551?v=3","gravatar_id":"","url":"https://api.github.com/users/crosbymichael","html_url":"https://github.com/crosbymichael","followers_url":"https://api.github.com/users/crosbymichael/followers","following_url":"https://api.github.com/users/crosbymichael/following{/other_user}","gists_url":"https://api.github.com/users/crosbymichael/gists{/gist_id}","starred_url":"https://api.github.com/users/crosbymichael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crosbymichael/subscriptions","organizations_url":"https://api.github.com/users/crosbymichael/orgs","repos_url":"https://api.github.com/users/crosbymichael/repos","events_url":"https://api.github.com/users/crosbymichael/events{/privacy}","received_events_url":"https://api.github.com/users/crosbymichael/received_events","type":"User","site_admin":false},"open_issues":20,"closed_issues":8,"state":"open","created_at":"2016-02-05T01:11:25Z","updated_at":"2016-02-19T03:27:39Z","due_on":"2016-03-03T08:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/opencontainers/runc/pulls/571/commits","review_comments_url":"https://api.github.com/repos/opencontainers/runc/pulls/571/comments","review_comment_url":"https://api.github.com/repos/opencontainers/runc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/opencontainers/runc/issues/571/comments","statuses_url":"https://api.github.com/repos/opencontainers/runc/statuses/6aeedac655c11255c697008317bd0196fb03dc79","head":{"label":"mikebrow:runc-list-format-options","ref":"runc-list-format-options","sha":"6aeedac655c11255c697008317bd0196fb03dc79","user":{"login":"mikebrow","id":12767641,"avatar_url":"https://avatars.githubusercontent.com/u/12767641?v=3","gravatar_id":"","url":"https://api.github.com/users/mikebrow","html_url":"https://github.com/mikebrow","followers_url":"https://api.github.com/users/mikebrow/followers","following_url":"https://api.github.com/users/mikebrow/following{/other_user}","gists_url":"https://api.github.com/users/mikebrow/gists{/gist_id}","starred_url":"https://api.github.com/users/mikebrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikebrow/subscriptions","organizations_url":"https://api.github.com/users/mikebrow/orgs","repos_url":"https://api.github.com/users/mikebrow/repos","events_url":"https://api.github.com/users/mikebrow/events{/privacy}","received_events_url":"https://api.github.com/users/mikebrow/received_events","type":"User","site_admin":false},"repo":{"id":43705219,"name":"runc","full_name":"mikebrow/runc","owner":{"login":"mikebrow","id":12767641,"avatar_url":"https://avatars.githubusercontent.com/u/12767641?v=3","gravatar_id":"","url":"https://api.github.com/users/mikebrow","html_url":"https://github.com/mikebrow","followers_url":"https://api.github.com/users/mikebrow/followers","following_url":"https://api.github.com/users/mikebrow/following{/other_user}","gists_url":"https://api.github.com/users/mikebrow/gists{/gist_id}","starred_url":"https://api.github.com/users/mikebrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikebrow/subscriptions","organizations_url":"https://api.github.com/users/mikebrow/orgs","repos_url":"https://api.github.com/users/mikebrow/repos","events_url":"https://api.github.com/users/mikebrow/events{/privacy}","received_events_url":"https://api.github.com/users/mikebrow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mikebrow/runc","description":"runc container cli tools","fork":true,"url":"https://api.github.com/repos/mikebrow/runc","forks_url":"https://api.github.com/repos/mikebrow/runc/forks","keys_url":"https://api.github.com/repos/mikebrow/runc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mikebrow/runc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mikebrow/runc/teams","hooks_url":"https://api.github.com/repos/mikebrow/runc/hooks","issue_events_url":"https://api.github.com/repos/mikebrow/runc/issues/events{/number}","events_url":"https://api.github.com/repos/mikebrow/runc/events","assignees_url":"https://api.github.com/repos/mikebrow/runc/assignees{/user}","branches_url":"https://api.github.com/repos/mikebrow/runc/branches{/branch}","tags_url":"https://api.github.com/repos/mikebrow/runc/tags","blobs_url":"https://api.github.com/repos/mikebrow/runc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mikebrow/runc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mikebrow/runc/git/refs{/sha}","trees_url":"https://api.github.com/repos/mikebrow/runc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mikebrow/runc/statuses/{sha}","languages_url":"https://api.github.com/repos/mikebrow/runc/languages","stargazers_url":"https://api.github.com/repos/mikebrow/runc/stargazers","contributors_url":"https://api.github.com/repos/mikebrow/runc/contributors","subscribers_url":"https://api.github.com/repos/mikebrow/runc/subscribers","subscription_url":"https://api.github.com/repos/mikebrow/runc/subscription","commits_url":"https://api.github.com/repos/mikebrow/runc/commits{/sha}","git_commits_url":"https://api.github.com/repos/mikebrow/runc/git/commits{/sha}","comments_url":"https://api.github.com/repos/mikebrow/runc/comments{/number}","issue_comment_url":"https://api.github.com/repos/mikebrow/runc/issues/comments{/number}","contents_url":"https://api.github.com/repos/mikebrow/runc/contents/{+path}","compare_url":"https://api.github.com/repos/mikebrow/runc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mikebrow/runc/merges","archive_url":"https://api.github.com/repos/mikebrow/runc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mikebrow/runc/downloads","issues_url":"https://api.github.com/repos/mikebrow/runc/issues{/number}","pulls_url":"https://api.github.com/repos/mikebrow/runc/pulls{/number}","milestones_url":"https://api.github.com/repos/mikebrow/runc/milestones{/number}","notifications_url":"https://api.github.com/repos/mikebrow/runc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mikebrow/runc/labels{/name}","releases_url":"https://api.github.com/repos/mikebrow/runc/releases{/id}","deployments_url":"https://api.github.com/repos/mikebrow/runc/deployments","created_at":"2015-10-05T18:32:02Z","updated_at":"2016-01-22T22:21:22Z","pushed_at":"2016-02-19T04:00:55Z","git_url":"git://github.com/mikebrow/runc.git","ssh_url":"git@github.com:mikebrow/runc.git","clone_url":"https://github.com/mikebrow/runc.git","svn_url":"https://github.com/mikebrow/runc","homepage":"","size":2521,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"opencontainers:master","ref":"master","sha":"0107c7fb6cef8d2f302f299039cc2f9a903880ac","user":{"login":"opencontainers","id":12563465,"avatar_url":"https://avatars.githubusercontent.com/u/12563465?v=3","gravatar_id":"","url":"https://api.github.com/users/opencontainers","html_url":"https://github.com/opencontainers","followers_url":"https://api.github.com/users/opencontainers/followers","following_url":"https://api.github.com/users/opencontainers/following{/other_user}","gists_url":"https://api.github.com/users/opencontainers/gists{/gist_id}","starred_url":"https://api.github.com/users/opencontainers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencontainers/subscriptions","organizations_url":"https://api.github.com/users/opencontainers/orgs","repos_url":"https://api.github.com/users/opencontainers/repos","events_url":"https://api.github.com/users/opencontainers/events{/privacy}","received_events_url":"https://api.github.com/users/opencontainers/received_events","type":"Organization","site_admin":false},"repo":{"id":36960321,"name":"runc","full_name":"opencontainers/runc","owner":{"login":"opencontainers","id":12563465,"avatar_url":"https://avatars.githubusercontent.com/u/12563465?v=3","gravatar_id":"","url":"https://api.github.com/users/opencontainers","html_url":"https://github.com/opencontainers","followers_url":"https://api.github.com/users/opencontainers/followers","following_url":"https://api.github.com/users/opencontainers/following{/other_user}","gists_url":"https://api.github.com/users/opencontainers/gists{/gist_id}","starred_url":"https://api.github.com/users/opencontainers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opencontainers/subscriptions","organizations_url":"https://api.github.com/users/opencontainers/orgs","repos_url":"https://api.github.com/users/opencontainers/repos","events_url":"https://api.github.com/users/opencontainers/events{/privacy}","received_events_url":"https://api.github.com/users/opencontainers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/opencontainers/runc","description":"runc container cli tools","fork":false,"url":"https://api.github.com/repos/opencontainers/runc","forks_url":"https://api.github.com/repos/opencontainers/runc/forks","keys_url":"https://api.github.com/repos/opencontainers/runc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opencontainers/runc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opencontainers/runc/teams","hooks_url":"https://api.github.com/repos/opencontainers/runc/hooks","issue_events_url":"https://api.github.com/repos/opencontainers/runc/issues/events{/number}","events_url":"https://api.github.com/repos/opencontainers/runc/events","assignees_url":"https://api.github.com/repos/opencontainers/runc/assignees{/user}","branches_url":"https://api.github.com/repos/opencontainers/runc/branches{/branch}","tags_url":"https://api.github.com/repos/opencontainers/runc/tags","blobs_url":"https://api.github.com/repos/opencontainers/runc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opencontainers/runc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opencontainers/runc/git/refs{/sha}","trees_url":"https://api.github.com/repos/opencontainers/runc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opencontainers/runc/statuses/{sha}","languages_url":"https://api.github.com/repos/opencontainers/runc/languages","stargazers_url":"https://api.github.com/repos/opencontainers/runc/stargazers","contributors_url":"https://api.github.com/repos/opencontainers/runc/contributors","subscribers_url":"https://api.github.com/repos/opencontainers/runc/subscribers","subscription_url":"https://api.github.com/repos/opencontainers/runc/subscription","commits_url":"https://api.github.com/repos/opencontainers/runc/commits{/sha}","git_commits_url":"https://api.github.com/repos/opencontainers/runc/git/commits{/sha}","comments_url":"https://api.github.com/repos/opencontainers/runc/comments{/number}","issue_comment_url":"https://api.github.com/repos/opencontainers/runc/issues/comments{/number}","contents_url":"https://api.github.com/repos/opencontainers/runc/contents/{+path}","compare_url":"https://api.github.com/repos/opencontainers/runc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opencontainers/runc/merges","archive_url":"https://api.github.com/repos/opencontainers/runc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opencontainers/runc/downloads","issues_url":"https://api.github.com/repos/opencontainers/runc/issues{/number}","pulls_url":"https://api.github.com/repos/opencontainers/runc/pulls{/number}","milestones_url":"https://api.github.com/repos/opencontainers/runc/milestones{/number}","notifications_url":"https://api.github.com/repos/opencontainers/runc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opencontainers/runc/labels{/name}","releases_url":"https://api.github.com/repos/opencontainers/runc/releases{/id}","deployments_url":"https://api.github.com/repos/opencontainers/runc/deployments","created_at":"2015-06-05T23:30:45Z","updated_at":"2016-02-18T19:29:22Z","pushed_at":"2016-02-19T04:00:55Z","git_url":"git://github.com/opencontainers/runc.git","ssh_url":"git@github.com:opencontainers/runc.git","clone_url":"https://github.com/opencontainers/runc.git","svn_url":"https://github.com/opencontainers/runc","homepage":"","size":4704,"stargazers_count":2513,"watchers_count":2513,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":305,"mirror_url":null,"open_issues_count":47,"forks":305,"open_issues":47,"watchers":2513,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/571"},"html":{"href":"https://github.com/opencontainers/runc/pull/571"},"issue":{"href":"https://api.github.com/repos/opencontainers/runc/issues/571"},"comments":{"href":"https://api.github.com/repos/opencontainers/runc/issues/571/comments"},"review_comments":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/571/comments"},"review_comment":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/opencontainers/runc/pulls/571/commits"},"statuses":{"href":"https://api.github.com/repos/opencontainers/runc/statuses/6aeedac655c11255c697008317bd0196fb03dc79"}}}}