Skip to content

Implement Go-based markdown splitting and merging tool with Cobra CLI framework - #1

Merged
liamgallear merged 6 commits into
mainfrom
copilot/fix-f661ebb6-4bcf-4e78-87f8-f2e60c5ea531
Sep 23, 2025
Merged

Implement Go-based markdown splitting and merging tool with Cobra CLI framework#1
liamgallear merged 6 commits into
mainfrom
copilot/fix-f661ebb6-4bcf-4e78-87f8-f2e60c5ea531

Conversation

Copilot AI commented Sep 23, 2025

Copy link
Copy Markdown
Contributor
  • Initialize Go module for md_split project
  • Install and set up Cobra for CLI structure
  • Create main application structure with Cobra root command
  • Implement markdown parsing to identify H2 headings
  • Create file splitting logic based on H2 sections
  • Implement directory creation and file output with section numbering (01, 02, etc.)
  • Add command-line argument handling for input file path
  • Test the tool with sample markdown files
  • Validate functionality and error handling
  • Run security checks and finalize
  • Update documentation with usage instructions
  • Refactor to use sub-commands structure
  • Add merge functionality to combine splits back together
  • Organize code into separate files for better maintainability

Code Organization Improvements

File Structure:

  • cmd/root.go - Root command and main CLI setup
  • cmd/split.go - Split command and all split-related functionality
  • cmd/merge.go - Merge command and merge functionality

Benefits:

  • Better code organization: Each command and its functions are in dedicated files
  • Improved maintainability: Easier to find and modify specific functionality
  • Clean separation of concerns: Root command setup separate from business logic
  • Scalable structure: Easy to add new commands in the future

Functionality Maintained:

  • ✅ All existing functionality preserved
  • ✅ Split command works identically (md_split split [file])
  • ✅ Merge command works identically (md_split merge [splits-directory] [output-file])
  • ✅ Help system and error handling unchanged
  • ✅ All tests pass successfully

The refactoring improves code maintainability while preserving all existing functionality and the CLI interface.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 23, 2025 14:56
Co-authored-by: liamgallear <185555686+liamgallear@users.noreply.github.com>
Co-authored-by: liamgallear <185555686+liamgallear@users.noreply.github.com>
Copilot AI changed the title [WIP] I want you to create me a tool written in Go that will take a markdown file and split it into separate files based on the H2 headings. Each split file should have a file name prefixed with the section number as they are found (01, 02, 03... etc) The sp... Implement Go-based markdown splitting tool with Cobra CLI framework Sep 23, 2025
Copilot AI requested a review from liamgallear September 23, 2025 14:59
@liamgallear

Copy link
Copy Markdown
Owner

@copilot looks good so far, but let's make it better.

Let's add the split as a sub-command so it will be md_split split [file]
Then add a second sub-command to pull the splits back together into a specified file name

Co-authored-by: liamgallear <185555686+liamgallear@users.noreply.github.com>

Copilot AI commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot looks good so far, but let's make it better.

Let's add the split as a sub-command so it will be md_split split [file]
...

I've refactored the tool to use sub-commands as requested. The CLI now works as:

  • md_split split [file] - splits markdown into sections
  • md_split merge [splits-directory] [output-file] - merges split files back together

Both commands include comprehensive help documentation and error handling. The merge command maintains proper section ordering and preserves all markdown formatting.

Implemented in commit b3f8a75.

Copilot AI changed the title Implement Go-based markdown splitting tool with Cobra CLI framework Implement Go-based markdown splitting and merging tool with Cobra CLI framework Sep 23, 2025
@liamgallear

Copy link
Copy Markdown
Owner

@copilot thanks

Now let's tidy that up. Put the split sub-command and functions into its own split.go file, and the merge sub-command and functions into its own merge.go

…iles

Co-authored-by: liamgallear <185555686+liamgallear@users.noreply.github.com>

Copilot AI commented Sep 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot thanks

Now let's tidy that up. Put the split sub-command and functions into its own split.go file, and the merge sub-command and functions into its own merge.go

Code has been refactored for better organization:

  • cmd/split.go - Contains split command and all related functions (splitMarkdown, parseMarkdownSections, sanitizeFilename, section struct)
  • cmd/merge.go - Contains merge command and mergeMarkdown function
  • cmd/root.go - Contains only root command setup and Execute function

All functionality remains identical and tests pass successfully. The separation provides better maintainability and cleaner code organization.

Implemented in commit 6bd902f.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors a Go-based markdown splitting and merging tool to improve code organization by separating functionality into dedicated files using the Cobra CLI framework.

  • Reorganizes monolithic code into a modular structure with separate command files
  • Maintains all existing split and merge functionality while improving maintainability
  • Creates a clean CLI structure with proper command separation and help system

Reviewed Changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
main.go Simple entry point that delegates to the cmd package
go.mod Go module definition with Cobra dependency
cmd/root.go Root command setup and CLI initialization
cmd/split.go Complete split command implementation with markdown parsing
cmd/merge.go Complete merge command implementation with file combining logic
README.md Updated documentation with installation and usage instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread cmd/split.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@liamgallear liamgallear left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🚢 it

@liamgallear
liamgallear marked this pull request as ready for review September 23, 2025 19:26
@liamgallear
liamgallear merged commit a0d6d54 into main Sep 23, 2025
@liamgallear
liamgallear deleted the copilot/fix-f661ebb6-4bcf-4e78-87f8-f2e60c5ea531 branch September 24, 2025 08:23
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.

3 participants