Skip to content

Add signup, document create/update commands#1372

Merged
hackerwins merged 9 commits into
yorkie-team:mainfrom
KMSstudio:main
Jul 9, 2025
Merged

Add signup, document create/update commands#1372
hackerwins merged 9 commits into
yorkie-team:mainfrom
KMSstudio:main

Conversation

@KMSstudio

@KMSstudio KMSstudio commented Jul 8, 2025

Copy link
Copy Markdown
Member

What this PR does / why we need it:

Adds three new CLI commands: signup, document create, and document update.

  • signup: Provides a minimal CLI interface to call admin.Client.SignUp.
  • document create: Adds the ability to create a new document using admin.Client.CreateDocument, with optional --initial-root YSON content.
  • document update: Allows modifying the root of an existing document via the --root flag using parsed YSON. Uses admin.Client.UpdateDocument.

Which issue(s) this PR fixes:

Fixes #1367

Special notes for your reviewer:

I'm unsure about the current behavior of the document update command.
When using admin.Client.UpdateDocument, it seems that the existing root content remains intact, and the --update-root data is merged on top of it.
However, I originally understood this command to replace the entire document root with the new YSON content provided via --update-root.

Could you confirm whether this behavior is expected? If not, should the update logic explicitly clear the root before applying the new content?

Also, regarding the document create command: if --initial-root is not provided by the user, the code uses the default example document defined in the Yorkie documentation here.

The signup command was added primarily for testing purposes. It provides a minimal CLI interface to call admin.Client.SignUp, which helps verify client.go behavior. The signup.go currently reuses global variables (username, password, rpcAddr, insecure) and the readPassword() function from login.go. This reuse was intentional to avoid code duplication.

Does this PR introduce a user-facing change?:

Added three CLI commands: `signup`, `document create`, and `document update`.

Additional documentation:

  yorkie signup -u username  
  yorkie document create [project name] [document key]  
  yorkie document update [project name] [document key] --root <yson>

Checklist:

  • Added relevant tests or not required
  • Addressed and resolved all CodeRabbit review comments
  • Didn't break anything

Summary by CodeRabbit

  • New Features
    • Added a CLI command to create a new document within a specified project, supporting an optional initial root value.
    • Introduced a CLI command to update an existing document's root value in a project.
    • Added a CLI command for user signup, allowing users to register with a username and optional password.

KMSstudio added 3 commits July 8, 2025 18:04
This command allows users to create a new document in a specified
project using the CLI. It accepts an optional --initial-root flag
to define the document’s initial YSON content. If the flag is not
provided, a default sample object is used that includes all major
CRDT value types such as Counter, Text, Tree, BinData, and Date.

The command uses admin.Client.CreateDocument and handles YSON
parsing using yson.ParseObject. This improves scripting and local
testing usability, especially when working with sled-hosted servers
or during development without relying on the web console.
This command uses admin.Client.SignUp to create a user, and was
added primarily to test the behavior of client.go, including client
activation and document attachment, in isolation from the full CLI
flow.
This command updates an existing document’s root using the Yorkie
CLI. It allows users to specify YSON input with the `--root`
flag, enabling structured changes to fields such as Counter, Text,
or Tree nodes. The command uses admin.Client.UpdateDocument
and yson.ParseObject to apply the changes.
@CLAassistant

CLAassistant commented Jul 8, 2025

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 8, 2025

Copy link
Copy Markdown

"""

Walkthrough

Two new CLI subcommands, create and update, have been added to the Yorkie document command group. The create command allows creating a new document with an optional initial root, while the update command enables updating an existing document’s root. A new signup command for user registration is also introduced.

Changes

File(s) Change Summary
cmd/yorkie/document/create.go Added create subcommand for documents, supporting project name, document key, and initial root.
cmd/yorkie/document/update.go Added update subcommand for documents, supporting project name, document key, and new root flag.
cmd/yorkie/signup.go Introduced signup command for user registration with username and password options.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant YorkieAdminClient
    User->>CLI: yorkie document create [project] [key] --initial-root '<YSON>'
    CLI->>CLI: Parse args & flags
    CLI->>YorkieAdminClient: CreateDocument(project, key, root)
    YorkieAdminClient-->>CLI: Document created (ID, key)
    CLI-->>User: Print document key and ID
Loading
sequenceDiagram
    participant User
    participant CLI
    participant YorkieAdminClient
    User->>CLI: yorkie document update [project] [key] --root '<YSON>'
    CLI->>CLI: Parse args & flags
    CLI->>YorkieAdminClient: UpdateDocument(project, key, root)
    YorkieAdminClient-->>CLI: Document updated (ID, key)
    CLI-->>User: Print confirmation
Loading

Assessment against linked issues

Objective Addressed Explanation
Add create command to Yorkie CLI for documents with optional --initial-root flag (#1367)
Add update command to Yorkie CLI for documents with required --root flag (#1367)
Support argument validation and error handling for both commands (#1367)
Register new commands under the correct CLI command group (#1367)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of signup command for user registration (cmd/yorkie/signup.go) The signup command is unrelated to document creation or update and is not mentioned in #1367.
"""

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13e8a89 and dc097a2.

📒 Files selected for processing (2)
  • cmd/yorkie/document/create.go (1 hunks)
  • cmd/yorkie/document/update.go (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: KMSstudio
PR: yorkie-team/yorkie#1372
File: cmd/yorkie/signup.go:0-0
Timestamp: 2025-07-09T01:45:42.906Z
Learning: In the Yorkie CLI codebase (cmd/yorkie/), global variables like `username`, `password`, `rpcAddr`, and `insecure` are declared in `login.go` at package level and are reused across different commands (like `signup.go`) within the same `main` package, avoiding unnecessary duplication.
Learnt from: KMSstudio
PR: yorkie-team/yorkie#1372
File: cmd/yorkie/signup.go:0-0
Timestamp: 2025-07-09T01:45:42.906Z
Learning: In the Yorkie CLI codebase, global variables like `username`, `password`, `rpcAddr`, and `insecure` are declared in `login.go` at package level and are reused across different commands (like `signup.go`) within the same `main` package, avoiding unnecessary duplication.
cmd/yorkie/document/create.go (4)
Learnt from: KMSstudio
PR: yorkie-team/yorkie#1372
File: cmd/yorkie/signup.go:0-0
Timestamp: 2025-07-09T01:45:42.906Z
Learning: In the Yorkie CLI codebase (cmd/yorkie/), global variables like `username`, `password`, `rpcAddr`, and `insecure` are declared in `login.go` at package level and are reused across different commands (like `signup.go`) within the same `main` package, avoiding unnecessary duplication.
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.326Z
Learning: In `pkg/document/change/id.go`, the `InitialID` variable represents the initial state where nothing has been edited. Consider using a function like `GetInitialID()` instead of the package-level variable to enforce proper initialization and prevent shared mutable state.
Learnt from: window9u
PR: yorkie-team/yorkie#1156
File: server/backend/config.go:235-266
Timestamp: 2025-02-20T00:58:21.388Z
Learning: In Yorkie server, configuration parsing methods (e.g., `ParseEventWebhookMaxWaitInterval`) use `os.Exit(1)` for error handling as they are executed during server initialization where early termination on invalid configuration is desired.
Learnt from: hackerwins
PR: yorkie-team/yorkie#1036
File: cluster/client.go:85-91
Timestamp: 2024-10-17T06:32:06.874Z
Learning: In Go, when wrapping errors using fmt.Errorf, it's against convention to include 'failed to' as a prefix in the error message.
cmd/yorkie/document/update.go (5)
Learnt from: KMSstudio
PR: yorkie-team/yorkie#1372
File: cmd/yorkie/signup.go:0-0
Timestamp: 2025-07-09T01:45:42.906Z
Learning: In the Yorkie CLI codebase (cmd/yorkie/), global variables like `username`, `password`, `rpcAddr`, and `insecure` are declared in `login.go` at package level and are reused across different commands (like `signup.go`) within the same `main` package, avoiding unnecessary duplication.
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.326Z
Learning: In `pkg/document/change/id.go`, the `InitialID` variable represents the initial state where nothing has been edited. Consider using a function like `GetInitialID()` instead of the package-level variable to enforce proper initialization and prevent shared mutable state.
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-21T04:54:17.948Z
Learning: In the Yorkie project, the `VersionVector.Min` and `VersionVector.Max` methods should maintain consistent behavior and documentation. Both methods should modify the receiver in-place for memory efficiency, take pointer parameters, and document their side effects clearly.
Learnt from: hackerwins
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-20T11:31:21.714Z
Learning: In the Yorkie project, the `VersionVector.Max` method modifies the receiver in-place and returns it, which is an intentional design decision for memory efficiency. The method takes a pointer parameter but only reads from it, maintaining input integrity.
Learnt from: hackerwins
PR: yorkie-team/yorkie#1036
File: cluster/client.go:85-91
Timestamp: 2024-10-17T06:32:06.874Z
Learning: In Go, when wrapping errors using fmt.Errorf, it's against convention to include 'failed to' as a prefix in the error message.
🧬 Code Graph Analysis (1)
cmd/yorkie/document/update.go (3)
cmd/yorkie/config/config.go (1)
  • LoadAuth (74-86)
admin/client.go (1)
  • WithInsecure (54-56)
server/documents/documents.go (1)
  • UpdateDocument (379-469)
🪛 ast-grep (0.38.1)
cmd/yorkie/document/create.go

[warning] 56-59: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

cmd/yorkie/document/update.go

[warning] 57-61: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(
rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
cmd/yorkie/document/create.go (2)

34-34: Good improvement on the default YSON

The simplified default "{}" is much better than the complex example that was initially suggested. This provides a clean, empty starting point for users.


36-83: Well-structured CLI command implementation

The command structure follows good CLI patterns with proper argument validation, configuration loading, and error handling. The optional --initial-root flag provides good flexibility for users.

cmd/yorkie/document/update.go (3)

34-78: Solid CLI command implementation

The update command is well-structured with proper argument validation, required flag handling, and clear error messages. The implementation follows established patterns from the codebase.


38-46: Excellent input validation

The dual validation approach checking both argument count and required flag presence provides clear, specific error messages to users.


80-90: Good flag configuration

Properly marks the --root flag as required and provides clear description. The flag setup is clean and follows CLI best practices.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hackerwins hackerwins requested a review from Copilot July 8, 2025 09:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (6)
cmd/yorkie/signup.go (3)

34-36: Consider adding password validation.

The readPassword() function is called without any validation of the password strength or format. Consider adding basic password requirements (minimum length, etc.) to improve security.


84-84: Handle the error from MarkFlagRequired.

The return value from cmd.MarkFlagRequired("username") is being ignored. While this is unlikely to fail, it's better to handle the error for completeness.

-	_ = cmd.MarkFlagRequired("username")
+	if err := cmd.MarkFlagRequired("username"); err != nil {
+		panic(fmt.Sprintf("failed to mark username flag as required: %v", err))
+	}

1-1: Fix code formatting.

The static analysis tool indicates the file is not properly formatted. Please run gofmt on this file to ensure consistent formatting.

gofmt -w cmd/yorkie/signup.go
cmd/yorkie/document/create.go (1)

1-1: Fix code formatting.

The static analysis tool indicates the file is not properly formatted. Please run gofmt on this file to ensure consistent formatting.

gofmt -w cmd/yorkie/document/create.go
cmd/yorkie/document/update.go (2)

87-87: Handle the error from MarkFlagRequired.

The return value from cmd.MarkFlagRequired("root") is being ignored. While this is unlikely to fail, it's better to handle the error for completeness.

-	_ = cmd.MarkFlagRequired("root")
+	if err := cmd.MarkFlagRequired("root"); err != nil {
+		panic(fmt.Sprintf("failed to mark root flag as required: %v", err))
+	}

1-1: Fix code formatting.

The static analysis tool indicates the file is not properly formatted. Please run gofmt on this file to ensure consistent formatting.

gofmt -w cmd/yorkie/document/update.go
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 679ac7f and 52d904a.

📒 Files selected for processing (3)
  • cmd/yorkie/document/create.go (1 hunks)
  • cmd/yorkie/document/update.go (1 hunks)
  • cmd/yorkie/signup.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
cmd/yorkie/signup.go (3)
cmd/yorkie/config/config.go (1)
  • Preload (155-176)
admin/client.go (1)
  • WithInsecure (54-56)
server/users/users.go (1)
  • SignUp (30-47)
cmd/yorkie/document/update.go (3)
cmd/yorkie/config/config.go (1)
  • LoadAuth (74-86)
admin/client.go (1)
  • WithInsecure (54-56)
server/documents/documents.go (1)
  • UpdateDocument (379-469)
🪛 ast-grep (0.38.1)
cmd/yorkie/signup.go

[warning] 37-37: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(rpcAddr, admin.WithInsecure(insecure))
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

cmd/yorkie/document/update.go

[warning] 56-60: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(
rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

cmd/yorkie/document/create.go

[warning] 69-72: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

🪛 golangci-lint (1.64.8)
cmd/yorkie/signup.go

1-1: File is not properly formatted

(gofmt)

cmd/yorkie/document/update.go

1-1: File is not properly formatted

(gofmt)

cmd/yorkie/document/create.go

1-1: File is not properly formatted

(gofmt)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (5)
cmd/yorkie/signup.go (1)

28-54: Well-structured CLI command with good error handling.

The signup command implementation follows good practices with proper error handling and resource cleanup. The use of defer cli.Close() ensures the connection is properly closed.

cmd/yorkie/document/create.go (2)

49-98: Well-structured document creation command.

The command follows good practices with proper argument validation, authentication loading, and resource cleanup. The use of a default YSON example is helpful for users.


33-47: Comprehensive default YSON example.

The default YSON example covers all major data types and is well-structured. This will be helpful for users learning the YSON format.

cmd/yorkie/document/update.go (2)

33-77: Well-structured document update command with good validation.

The command properly validates required arguments and flags, loads authentication, and handles errors appropriately. The use of key.Key() conversion is correct for the document key parameter.


37-45: Excellent argument validation logic.

The validation function properly checks for both the required positional arguments and the required --root flag. This provides clear error messages to users.

Comment thread cmd/yorkie/document/create.go Outdated
Comment thread cmd/yorkie/document/update.go Outdated
Resolved formatting and style issues reported by `golangci-lint`,
including gofmt violations and minor inconsistencies in comments,
imports, and code structure.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Adds three new CLI commands to the Yorkie tooling for user signup and document management via the admin API.

  • Implements a signup command to register a new user.
  • Introduces document create allowing an optional YSON initial root or a default example.
  • Adds document update to replace a document’s root using a required YSON string.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
cmd/yorkie/signup.go New CLI command for user signup
cmd/yorkie/document/create.go New create command with optional default YSON
cmd/yorkie/document/update.go New update command requiring a --root flag
Comments suppressed due to low confidence (2)

cmd/yorkie/document/create.go:34

  • This new create command lacks unit tests for flag parsing and error conditions (e.g., invalid YSON input); consider adding tests to validate its behavior.
func newCreateDocumentCmd() *cobra.Command {

cmd/yorkie/document/update.go:32

  • This new update command also lacks unit tests for flag parsing, argument validation, and error conditions; consider adding tests to ensure its robustness.
		RunE: func(cmd *cobra.Command, args []string) error {

Comment thread cmd/yorkie/document/create.go Outdated
Comment thread cmd/yorkie/document/create.go Outdated
Comment thread cmd/yorkie/signup.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
cmd/yorkie/document/create.go (1)

71-71: Handle YSON parse errors by using Unmarshal instead of ParseObject

The current call to yson.ParseObject will panic on invalid input. Since there is no ParseObjectWithError helper in the yson package, switch to yson.Unmarshal, which returns an error you can handle gracefully.

-	obj := yson.ParseObject(rootStr)
+	var obj yson.Object
+	if err := yson.Unmarshal(rootStr, &obj); err != nil {
+		return fmt.Errorf("failed to parse YSON: %w", err)
+	}
cmd/yorkie/document/update.go (1)

53-53: Clarify the empty schemaKey argument in UpdateDocument call

The final "" you're passing to cli.UpdateDocument is the schemaKey parameter. An empty string here tells the server to reuse the document's existing schema rather than updating it. Please add an inline comment or replace "" with a well-named constant to make this intent explicit.

For example:

-	doc, err := cli.UpdateDocument(ctx, projectName, key.Key(documentKey), updateRoot, "")
+	doc, err := cli.UpdateDocument(ctx, projectName, key.Key(documentKey), updateRoot, "" /* keep existing schema */)
🧹 Nitpick comments (3)
cmd/yorkie/signup.go (1)

1-1: Fix code formatting issues.

The file has formatting issues according to static analysis. Please run gofmt to ensure consistent formatting.

gofmt -w cmd/yorkie/signup.go
cmd/yorkie/document/create.go (1)

1-1: Fix code formatting issues.

The file has formatting issues according to static analysis. Please run gofmt to ensure consistent formatting.

gofmt -w cmd/yorkie/document/create.go
cmd/yorkie/document/update.go (1)

1-1: Fix code formatting issues.

The file has formatting issues according to static analysis. Please run gofmt to ensure consistent formatting.

gofmt -w cmd/yorkie/document/update.go
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52d904a and 14caa65.

📒 Files selected for processing (3)
  • cmd/yorkie/document/create.go (1 hunks)
  • cmd/yorkie/document/update.go (1 hunks)
  • cmd/yorkie/signup.go (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
cmd/yorkie/document/create.go (2)
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.326Z
Learning: In `pkg/document/change/id.go`, the `InitialID` variable represents the initial state where nothing has been edited. Consider using a function like `GetInitialID()` instead of the package-level variable to enforce proper initialization and prevent shared mutable state.
Learnt from: window9u
PR: yorkie-team/yorkie#1156
File: server/backend/config.go:235-266
Timestamp: 2025-02-20T00:58:21.388Z
Learning: In Yorkie server, configuration parsing methods (e.g., `ParseEventWebhookMaxWaitInterval`) use `os.Exit(1)` for error handling as they are executed during server initialization where early termination on invalid configuration is desired.
cmd/yorkie/document/update.go (2)
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: test/helper/helper.go:120-125
Timestamp: 2025-02-21T04:54:29.326Z
Learning: In `pkg/document/change/id.go`, the `InitialID` variable represents the initial state where nothing has been edited. Consider using a function like `GetInitialID()` instead of the package-level variable to enforce proper initialization and prevent shared mutable state.
Learnt from: chacha912
PR: yorkie-team/yorkie#1164
File: pkg/document/time/version_vector.go:158-183
Timestamp: 2025-02-21T04:54:17.948Z
Learning: In the Yorkie project, the `VersionVector.Min` and `VersionVector.Max` methods should maintain consistent behavior and documentation. Both methods should modify the receiver in-place for memory efficiency, take pointer parameters, and document their side effects clearly.
cmd/yorkie/signup.go (1)
Learnt from: window9u
PR: yorkie-team/yorkie#1156
File: server/backend/config.go:235-266
Timestamp: 2025-02-20T00:58:21.388Z
Learning: In Yorkie server, configuration parsing methods (e.g., `ParseEventWebhookMaxWaitInterval`) use `os.Exit(1)` for error handling as they are executed during server initialization where early termination on invalid configuration is desired.
🧬 Code Graph Analysis (1)
cmd/yorkie/signup.go (3)
cmd/yorkie/config/config.go (1)
  • Preload (155-176)
admin/client.go (1)
  • WithInsecure (54-56)
server/users/users.go (1)
  • SignUp (30-47)
🪛 ast-grep (0.38.1)
cmd/yorkie/document/create.go

[warning] 54-57: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

cmd/yorkie/document/update.go

[warning] 41-45: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(
rpcAddr,
admin.WithToken(auth.Token),
admin.WithInsecure(auth.Insecure),
)
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

cmd/yorkie/signup.go

[warning] 22-22: Found an insecure gRPC connection using 'grpc.WithInsecure()'. This creates a connection without encryption to a gRPC server. A malicious attacker could tamper with the gRPC message, which could compromise the machine. Instead, establish a secure connection with an SSL certificate using the 'grpc.WithTransportCredentials()' function. You can create a create credentials using a 'tls.Config{}' struct with 'credentials.NewTLS()'. The final fix looks like this: 'grpc.WithTransportCredentials(credentials.NewTLS())'.
Context: admin.Dial(rpcAddr, admin.WithInsecure(insecure))
Note: [CWE-300] Channel Accessible by Non-Endpoint. [REFERENCES]
- https://blog.gopheracademy.com/advent-2019/go-grps-and-tls/#connection-without-encryption

(grpc-client-insecure-connection-go)

🪛 golangci-lint (1.64.8)
cmd/yorkie/document/create.go

1-1: File is not properly formatted

(gofmt)

cmd/yorkie/document/update.go

1-1: File is not properly formatted

(gofmt)

cmd/yorkie/signup.go

1-1: File is not properly formatted

(gofmt)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
cmd/yorkie/signup.go (1)

19-19: readPassword function verified

I confirmed that readPassword() is implemented in cmd/yorkie/login.go (lines 88–99), so its invocation in cmd/yorkie/signup.go is valid. No further action needed here.

cmd/yorkie/document/create.go (1)

93-93: No action needed: SubCmd is correctly defined

The SubCmd variable is declared in cmd/yorkie/document/document.go (line 24), so it’s available throughout the package:

• cmd/yorkie/document/document.go:24 — SubCmd = &cobra.Command{…}

You can safely leave the SubCmd.AddCommand(cmd) call in create.go.

Likely an incorrect or invalid review comment.

cmd/yorkie/document/update.go (1)

73-73: No action needed – SubCmd is defined. In cmd/yorkie/document/document.go (around line 24), SubCmd = &cobra.Command{…} is declared, so the call in update.go is valid.

Likely an incorrect or invalid review comment.

Comment thread cmd/yorkie/signup.go Outdated
KMSstudio added 4 commits July 8, 2025 19:04
Resolved formatting and style issues reported by `golangci-lint`,
including gofmt violations and minor inconsistencies in comments,
imports, and code structure.
Removed unnecessary newline at line 18.
Also updated `document create` to handle possible errors from YSON parsing,
ensuring that parse failures do not cause unexpected panics.
Added Apache 2.0 license headers to relevant source files to clarify
licensing terms and ensure consistency across the codebase.

@hackerwins hackerwins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution.
I left a few comments.

Comment thread cmd/yorkie/document/create.go Outdated
Comment thread cmd/yorkie/document/update.go Outdated
Comment thread cmd/yorkie/document/create.go Outdated
Comment thread cmd/yorkie/document/create.go
@hackerwins hackerwins self-requested a review July 9, 2025 06:08

@hackerwins hackerwins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@hackerwins hackerwins changed the title Adds three new CLI commands: signup, document create, and document update to resolve issue #1367 Add signup, document create/update commands Jul 9, 2025
@hackerwins hackerwins merged commit cc959cb into yorkie-team:main Jul 9, 2025
5 of 6 checks passed
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.

Add create and update commands to yorkie document CLI

4 participants