// cmdPlaylist lists all playlists or contents of one playlist.
8056
func cmdPlaylist(session *sp.Session, args []string, abort <-chan bool) error {
	var f = flag.NewFlagSet(args[0], flag.ContinueOnError)
	opts := struct {
		offset, limit *int
	}{
		offset: f.Int("offset", 0, "result offset"),
		limit:  f.Int("limit", 10, "result count limitation"),
	}

	if err := f.Parse(args[1:]); err != nil {
		return err
	} else if f.NArg() >= 2 {
		return errors.New("too many arguments")
	}

	// TODO cancel wait when abort<-true
	if f.NArg() == 0 {
		playlists, err := session.Playlists()
		if err != nil {
			return err
		}
		playlists.Wait()

		println("###done playlisting")

		indent := 0
		for i := *opts.offset; i < playlists.Playlists() && i < *opts.limit; i++ {
			switch playlists.PlaylistType(i) {
			case sp.PlaylistTypeStartFolder:
				if folder, err := playlists.Folder(i); err == nil {
					print(strings.Repeat(" ", indent))
					println(folder.Name())
				}
				indent += 2
			case sp.PlaylistTypeEndFolder:
				indent -= 2
			case sp.PlaylistTypePlaylist:
				print(strings.Repeat(" ", indent))
				println(playlistStr(playlists.Playlist(i)))
			}
		}
	} else {
		var playlist *sp.Playlist

		// Argument is either uri or a playlist index
		if n, err := strconv.Atoi(f.Arg(0)); err == nil {
			playlists, err := session.Playlists()
			if err != nil {
				return err
			}
			playlists.Wait()
			// TODO do not panic on invalid index
			playlist = playlists.Playlist(n)
		} else {
			link, err := session.ParseLink(f.Arg(0))
			if err != nil {
				return err
			}
			if link.Type() != sp.LinkTypePlaylist {
				return errors.New("invalid link type")
			}
			playlist, err = link.Playlist()
			if err != nil {
				return err
			}
		}

		playlist.Wait()
		println(playlistStr(playlist))
		for i := *opts.offset; i < playlist.Tracks() && i < *opts.limit; i++ {
			pt := playlist.Track(i)
			println(trackStr(pt.Track()))
		}
	}

	return nil
}
635909
func (c *Client) PlaylistContents(name string) ([]Attrs, error) {
	return c.Command("listplaylistinfo %s", name).AttrsList("file")
}
1367099
func (cl Cmdline) ListAll() ([]string, error) {
	cmd := cl.commands.listAll()

	out, err := cl.runCommand(cmd, "List")
	if err != nil {
		return nil, errors.Trace(err)
	}
	out = strings.TrimSpace(out)

	if out == "" {
		return nil, nil
	}
	return strings.Split(out, "\n"), nil
}
1111013
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) {
	p, ok := s.daemon.PodList.Get(req.PodID)
	if !ok {
		return nil, fmt.Errorf("Pod not found")
	}

	return &types.PortMappingListResponse{
		PortMappings: p.ListPortMappings(),
	}, nil
}
239963
func (s *ServerMethods) GroupList() ([]*Group, error) {
	var groups []*Group
	if _, err := s.ExecCmd(NewCmd("servergrouplist").WithResponse(&groups)); err != nil {
		return nil, err
	}

	return groups, nil
}
423670
func (c *Client) PlaylistRename(name, newName string) error {
	return c.Command("rename %s %s", name, newName).OK()
}
768249
func (c *Client) PlaylistRemove(name string) error {
	return c.Command("rm %s", name).OK()
}
783892
func (s *HlsManifest) SetPlaylistWindowSeconds(v int64) *HlsManifest {
	s.PlaylistWindowSeconds = &v
	return s
}
834012
func (c *ServicedCli) cmdPoolList(ctx *cli.Context) {
	if len(ctx.Args()) > 0 {
		poolID := ctx.Args()[0]
		if pool, err := c.driver.GetResourcePool(poolID); err != nil {
			fmt.Fprintln(os.Stderr, err)
		} else if pool == nil {
			fmt.Fprintln(os.Stderr, "pool not found")
		} else if jsonPool, err := json.MarshalIndent(pool, " ", "  "); err != nil {
			fmt.Fprintf(os.Stderr, "failed to marshal resource pool: %s", err)
		} else {
			fmt.Println(string(jsonPool))
		}
		return
	}

	pools, err := c.driver.GetResourcePools()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	} else if pools == nil || len(pools) == 0 {
		fmt.Fprintln(os.Stderr, "no resource pools found")
		return
	}

	if ctx.Bool("verbose") {
		if jsonPool, err := json.MarshalIndent(pools, " ", "  "); err != nil {
			fmt.Fprintf(os.Stderr, "failed to marshal resource pool list: %s", err)
		} else {
			fmt.Println(string(jsonPool))
		}
	} else {
		t := NewTable(ctx.String("show-fields"))
		t.Padding = 6
		for _, p := range pools {
			perms := make([]string, 0)
			if p.HasDfsAccess() {
				perms = append(perms, "DFS")
			}
			if p.HasAdminAccess() {
				perms = append(perms, "Admin")
			}
			t.AddRow(map[string]interface{}{
				"ID":          p.ID,
				"Permissions": perms,
			})
		}
		t.Print()
	}
}
1217341
func (s *Service) AppList(ctx context.Context, lr *ListRange) (AppListResult, error) {
	var app AppListResult
	return app, s.Get(ctx, &app, fmt.Sprintf("/apps"), nil, lr)
}
510819
func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOptions) ([]types.Checkpoint, error) {
	var out []types.Checkpoint

	container, err := daemon.GetContainer(name)
	if err != nil {
		return nil, err
	}

	checkpointDir, err := getCheckpointDir(config.CheckpointDir, "", name, container.ID, container.CheckpointDir(), false)
	if err != nil {
		return nil, err
	}

	if err := os.MkdirAll(checkpointDir, 0755); err != nil {
		return nil, err
	}

	dirs, err := ioutil.ReadDir(checkpointDir)
	if err != nil {
		return nil, err
	}

	for _, d := range dirs {
		if !d.IsDir() {
			continue
		}
		cpt := types.Checkpoint{Name: d.Name()}
		out = append(out, cpt)
	}

	return out, nil
}
822584
func (c *Client) PlaylistAdd(name string, uri string) error {
	return c.Command("playlistadd %s %s", name, uri).OK()
}
581317
func (c *Client) PreviousPlaylistResults(s *SearchResult) error {
	if s.Playlists == nil || s.Playlists.Previous == "" {
		return ErrNoMorePages
	}
	return c.get(s.Playlists.Previous, s)
}
579242
func List(cmd *cli.Cmd) {
	var a []application.Application

	all := cmd.BoolOpt("a all", false, "List all applications, including archived")

	cmd.Action = func() {
		resp, body, errs := application.List()

		if errs != nil {
			log.Fatalf("Could not retrieve applications: %s", errs)
		}

		if resp.StatusCode != 200 {
			log.Fatalf("Could not retrieve applications: %s", resp.Status)
		}

		err := json.Unmarshal([]byte(body), &a)

		if err != nil {
			log.Fatal(err)
		}

		printAppBrief(a, *all)
	}
}
1269275
func (pc *PlaylistContainer) PlaylistType(n int) PlaylistType {
	if n < 0 || n >= pc.Playlists() {
		panic("spotify: playlist out of range")
	}
	return PlaylistType(C.sp_playlistcontainer_playlist_type(pc.sp_playlistcontainer, C.int(n)))
}
1008261
func (s *ServerRPC) ContainerList(ctx context.Context, req *types.ContainerListRequest) (*types.ContainerListResponse, error) {
	containerList, err := s.daemon.ListContainers(req.PodID, req.VmID)
	if err != nil {
		return nil, err
	}

	return &types.ContainerListResponse{
		ContainerList: containerList,
	}, nil
}
264324
func (c *Client) AppList(lr *ListRange) ([]App, error) {
	req, err := c.NewRequest("GET", "/apps", nil, nil)
	if err != nil {
		return nil, err
	}

	if lr != nil {
		lr.SetHeader(req)
	}

	var appsRes []App
	return appsRes, c.DoReq(req, &appsRes)
}