Skip to content

New flag#22

Merged
RohanAdwankar merged 4 commits intomasterfrom
new-flag
Oct 30, 2025
Merged

New flag#22
RohanAdwankar merged 4 commits intomasterfrom
new-flag

Conversation

@RohanAdwankar
Copy link
Owner

No description provided.

@RohanAdwankar
Copy link
Owner Author

Closes #14 and closes #19

@RohanAdwankar RohanAdwankar requested a review from Copilot October 29, 2025 23:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a new --new flag that allows users to create a new Mermaid diagram file and immediately launch the interactive editor. The implementation includes interactive graph type selection, automatic file naming with collision avoidance, and directory creation.

Key changes:

  • Added --new flag to create new diagrams with interactive editor launch
  • Implemented graph type selection using the dialoguer crate for interactive prompts
  • Added file path collision detection with automatic renaming (e.g., diagram1.mmd, diagram2.mmd)

Reviewed Changes

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

File Description
src/cli.rs Added --new flag, GraphType enum, select_graph_type() and ensure_unique_path() functions, and run_new() implementation
Cargo.toml Added dialoguer dependency and release profile optimizations
Cargo.lock Updated dependencies to include dialoguer and related transitive dependencies, plus general dependency version updates
Comments suppressed due to low confidence (1)

src/cli.rs:218

  • The run_render_or_edit_sync function doesn't check for the cli.new flag, which means it will silently ignore --new and fall through to run_render. This should bail with an error message similar to the --edit check to inform users that --new requires the 'server' feature.
pub fn run_render_or_edit_sync(cli: RenderArgs) -> Result<()> {
    if cli.edit {
        bail!("--edit requires the 'server' feature to be enabled");
    } else {
        run_render(cli)?;
    }
    Ok(())
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +272 to +283
if output.is_some() {
bail!("--new does not support specifying an output file");
}

if output_format.is_some() {
bail!("--new does not support selecting an output format");
}

if png {
bail!("--new does not support the --png flag");
}

Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

These runtime checks are redundant because lines 67 of the RenderArgs struct already define conflicts_with_all = [\"output\", \"output_format\", \"png\", \"edit\"] for the new flag. Clap will prevent these combinations at parse time, so these runtime checks will never be reached and can be removed.

Suggested change
if output.is_some() {
bail!("--new does not support specifying an output file");
}
if output_format.is_some() {
bail!("--new does not support selecting an output format");
}
if png {
bail!("--new does not support the --png flag");
}

Copilot uses AI. Check for mistakes.
Comment on lines +174 to +175
Some(ext) => format!("{stem}{counter}.{ext}"),
None => format!("{stem}{counter}"),
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

[nitpick] Missing separator between stem and counter in the generated filename. When a file diagram.mmd exists, this creates diagram1.mmd instead of diagram-1.mmd or diagram_1.mmd, which may be less readable. Consider adding a separator like - or _ for better file naming conventions.

Suggested change
Some(ext) => format!("{stem}{counter}.{ext}"),
None => format!("{stem}{counter}"),
Some(ext) => format!("{stem}-{counter}.{ext}"),
None => format!("{stem}-{counter}"),

Copilot uses AI. Check for mistakes.
Comment on lines +315 to +320
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {
bail!(
"diagram '{}' already exists; refusing to overwrite",
target_path.display()
);
}
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

This error case at lines 315-320 is unreachable because ensure_unique_path() at line 307 already guarantees that target_path doesn't exist. The AlreadyExists error can only occur in race condition scenarios where the file is created between the ensure_unique_path() check and the open() call.

Suggested change
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {
bail!(
"diagram '{}' already exists; refusing to overwrite",
target_path.display()
);
}

Copilot uses AI. Check for mistakes.

fn initial_contents(self) -> &'static str {
match self {
GraphType::Flowchart => "graph TD\nHello World!",
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

[nitpick] The initial diagram content uses a raw string with \\n which may not render correctly on Windows systems where line endings are \\r\\n. Consider using a multi-line string literal or platform-specific line endings.

Copilot uses AI. Check for mistakes.
@RohanAdwankar
Copy link
Owner Author

these seem like nitpicks, added redundancy isnt too big of a deal

@RohanAdwankar RohanAdwankar self-assigned this Oct 30, 2025
@RohanAdwankar RohanAdwankar merged commit 405377f into master Oct 30, 2025
7 checks passed
@RohanAdwankar RohanAdwankar deleted the new-flag branch October 30, 2025 00:36
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.

2 participants