Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating a collection [cli] #33

Merged
merged 3 commits into from
Aug 6, 2023
Merged

Conversation

StefMa
Copy link
Collaborator

@StefMa StefMa commented Aug 4, 2023

Fixes #14

This is just a basic usage of creating a collection.
The only supported option is the required "name".

Optional stuff will be added later.
Reference #29

./cli collection create [name] --apiKey [TOKEN] --baseUrl [URL]

You can check our internal outline instace for the collection named "stefmaTest".
This was done via the API:

{"id":"1aa656ac-b01f-4a5c-a35d-619aef20c36f","name":"stefmaTest","description":"","sort":{"direction":"asc","field":"index"},"index":"  8","color":"#FFBE0B","icon":"","permission":"","createdAt":"2023-08-04T11:02:37.635Z","updatedAt":"2023-08-04T11:02:37.635Z","deletedAt":"0001-01-01T00:00:00Z"}

You could also check this via the CLI 🤓

./cli collection fetch 1aa656ac-b01f-4a5c-a35d-619aef20c36f --apiKey [TOKEN] --baseUrl [URL]

internal/cli/cli.go Outdated Show resolved Hide resolved
internal/cli/cli.go Outdated Show resolved Hide resolved
@StefMa StefMa requested a review from rsjethani August 5, 2023 08:58
Copy link
Collaborator

@rsjethani rsjethani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply following changes then we are good to go:

diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index 8d8283f..10e5a04 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -24,7 +24,7 @@ func Run() error {
 }
 
 func rootCmd() *cobra.Command {
-       var rootCmd = &cobra.Command{Use: "outline"}
+       rootCmd := &cobra.Command{Use: "outline"}
 
        var apiKeyFlag string
        var baseUrlFlag string
@@ -45,7 +45,7 @@ func collectionCmd(rootCmd *cobra.Command) *cobra.Command {
        fetchSubCmd := collectionCmdFetch(rootCmd)
        collectionCmd.AddCommand(fetchSubCmd)
 
-       createSubCmd := collectionCmdCrate(rootCmd)
+       createSubCmd := collectionCmdCreate(rootCmd)
        collectionCmd.AddCommand(createSubCmd)
 
        return collectionCmd
@@ -73,7 +73,7 @@ func collectionCmdFetch(rootCmd *cobra.Command) *cobra.Command {
                                        return fmt.Errorf("can't get collection with id '%s': %w", colId, err)
                                }
 
-                               b, err := json.Marshal(&col)
+                               b, err := json.Marshal(col)
                                if err != nil {
                                        return fmt.Errorf("failed marshalling collection with id '%s: %w", colId, err)
                                }
@@ -84,7 +84,7 @@ func collectionCmdFetch(rootCmd *cobra.Command) *cobra.Command {
        }
 }
 
-func collectionCmdCrate(rootCmd *cobra.Command) *cobra.Command {
+func collectionCmdCreate(rootCmd *cobra.Command) *cobra.Command {
        return &cobra.Command{
                Use:   "create",
                Short: "Creates a collection",
@@ -107,7 +107,7 @@ func collectionCmdCrate(rootCmd *cobra.Command) *cobra.Command {
                                return fmt.Errorf("can't create collection with name '%s': %w", name, err)
                        }
 
-                       b, err := json.Marshal(&col)
+                       b, err := json.Marshal(col)
                        if err != nil {
                                return fmt.Errorf("failed marshalling collection with name '%s: %w", name, err)
                        }

@StefMa
Copy link
Collaborator Author

StefMa commented Aug 5, 2023

Applied the changes here and rebased with main 👍

@StefMa StefMa requested a review from rsjethani August 5, 2023 17:35
@StefMa StefMa merged commit 4bf018c into main Aug 6, 2023
3 checks passed
@StefMa StefMa deleted the cli-creation-collection branch August 6, 2023 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: create collections via cli
2 participants