Skip to content

Commit

Permalink
Add --only option to lh export command
Browse files Browse the repository at this point in the history
Add new --only option to lh export command which takes a
comma-separated list of Lighthouse project IDs/names.  If given, lh
export will only export the data of the specified Lighthouse projects.
  • Loading branch information
Niels Widger committed Mar 31, 2020
1 parent 99916b5 commit 4d6e979
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/lh/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"mime"
"os"
"path/filepath"
Expand All @@ -28,6 +29,7 @@ import (

type exportCmdOpts struct {
noAttachments bool
only []string
}

var exportCmdFlags exportCmdOpts
Expand All @@ -45,7 +47,15 @@ API requests, consider using -r and -b to rate limit API requests.
`,
Run: func(cmd *cobra.Command, args []string) {
flags := exportCmdFlags
_ = flags

only := map[int]bool{}
for _, projectStr := range flags.only {
id, err := ProjectID(projectStr)
if err != nil {
log.Fatal(err)
}
only[id] = true
}

account := Account()
base := filepath.Join(".", account)
Expand Down Expand Up @@ -97,6 +107,11 @@ API requests, consider using -r and -b to rate limit API requests.
fatalUsage(cmd, err)
}
for _, project := range ps {
// skip if project not in --only
if len(only) > 0 && !only[project.ID] {
continue
}

projectBase := filepath.Join(base, "projects", filename(fmt.Sprintf("%d-%s", project.ID, project.Permalink)))
writeDir(cmd, tw, projectBase)

Expand Down Expand Up @@ -363,4 +378,5 @@ func writeFile(cmd *cobra.Command, tw *tar.Writer, filename string, data []byte)
func init() {
RootCmd.AddCommand(exportCmd)
exportCmd.Flags().BoolVar(&exportCmdFlags.noAttachments, "no-attachments", false, "Don't include attachments in export")
exportCmd.Flags().StringSliceVar(&exportCmdFlags.only, "only", nil, "Only export data for the given comma-separated Lighthouse projects")
}

0 comments on commit 4d6e979

Please sign in to comment.