Skip to content

Commit 0335c97

Browse files
committed
Adjust get-project command to accept --expand
1 parent 1e2628c commit 0335c97

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

cmd/dev_server/projects.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ func NewGetProjectCmd(client resources.Client) *cobra.Command {
5252
cmd := &cobra.Command{
5353
GroupID: "projects",
5454
Args: validators.Validate(),
55-
Long: "get the specified project and its configuration for syncing from the LaunchDarkly Service",
56-
RunE: getProject(client),
57-
Short: "get a project",
58-
Use: "get-project",
55+
Long: `get the specified project and its configuration for syncing from the LaunchDarkly Service
56+
57+
Examples:
58+
# Get project with basic information
59+
ldcli dev-server get-project --project=my-project
60+
61+
# Get project with all data (for seeding/backup)
62+
ldcli dev-server get-project --project=my-project \
63+
--expand=overrides --expand=availableVariations > backup.json`,
64+
RunE: getProject(client),
65+
Short: "get a project",
66+
Use: "get-project",
5967
}
6068

6169
cmd.SetUsageTemplate(resourcescmd.SubcommandUsageTemplate())
@@ -65,17 +73,38 @@ func NewGetProjectCmd(client resources.Client) *cobra.Command {
6573
_ = cmd.Flags().SetAnnotation(cliflags.ProjectFlag, "required", []string{"true"})
6674
_ = viper.BindPFlag(cliflags.ProjectFlag, cmd.Flags().Lookup(cliflags.ProjectFlag))
6775

76+
cmd.Flags().StringSlice("expand", []string{}, "Expand options: overrides, availableVariations")
77+
_ = viper.BindPFlag("expand", cmd.Flags().Lookup("expand"))
78+
6879
return cmd
6980
}
7081

7182
func getProject(client resources.Client) func(*cobra.Command, []string) error {
7283
return func(cmd *cobra.Command, args []string) error {
7384

7485
path := getDevServerUrl() + "/dev/projects/" + viper.GetString(cliflags.ProjectFlag)
75-
res, err := client.MakeUnauthenticatedRequest(
86+
87+
// Add expand query parameters if specified
88+
// Try to get from command flags first, then fall back to viper
89+
expandOptions, err := cmd.Flags().GetStringSlice("expand")
90+
if err != nil {
91+
expandOptions = viper.GetStringSlice("expand")
92+
}
93+
94+
// Build query parameters
95+
query := make(map[string][]string)
96+
if len(expandOptions) > 0 {
97+
query["expand"] = expandOptions
98+
}
99+
100+
res, err := client.MakeRequest(
101+
"", // no auth token needed for dev server
76102
"GET",
77103
path,
78-
nil,
104+
"application/json",
105+
query,
106+
nil, // no body
107+
false, // not beta
79108
)
80109
if err != nil {
81110
return output.NewCmdOutputError(err, viper.GetString(cliflags.OutputFlag))

cmd/dev_server/seed.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@ func NewSeedCmd() *cobra.Command {
2222
cmd := &cobra.Command{
2323
GroupID: "projects",
2424
Args: validators.Validate(),
25-
Long: "Seed the dev server database from a JSON file. Database must be empty.",
26-
RunE: seed(),
27-
Short: "seed database from file",
28-
Use: "seed",
25+
Long: `Seed the dev server database from a JSON file. Database must be empty.
26+
27+
The JSON file format matches the output from:
28+
ldcli dev-server get-project --project=<key> \
29+
--expand=overrides --expand=availableVariations
30+
31+
Examples:
32+
# Export project data (while dev server is running)
33+
ldcli dev-server get-project --project=my-project \
34+
--expand=overrides --expand=availableVariations > backup.json
35+
36+
# Later, seed a clean database from backup
37+
ldcli dev-server seed --project=my-project --file=backup.json`,
38+
RunE: seed(),
39+
Short: "seed database from file",
40+
Use: "seed",
2941
}
3042

3143
cmd.SetUsageTemplate(resourcescmd.SubcommandUsageTemplate())

0 commit comments

Comments
 (0)