gomerge

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 6 Imported by: 0

README

gomerge - constructs for merging Go files

When dealing with over structured(to many directory and files) repositories, one route to tidying them is to merge files with related concepts. This often simplifies additional refactoring.

The provided cmd/gomerge removes the manual steps of concatenating go files and removing duplicate package imports.

Quick start

$ go install github.com/gregoryv/gomerge/cmd/gomerge@latest
$ gomerge -h
Usage: gomerge [OPTIONS] DST SRC
Options
  -i    include src filename in merged as comment
  -r    removes source after merge(only with -w)
  -w    writes result to destination file

Documentation

Overview

Package gomerge provides means to merge two go files removing duplicate imports.

Example
package main

import (
	"os"

	"github.com/gregoryv/gomerge"
)

func main() {
	cmd := gomerge.New(os.Stdout,
		[]byte(`package x

import "fmt"

func x() { fmt.Println("hello") }`),
		[]byte(`package x

import "strings"

func y() { strings.Repeat(" ", 10) }`),
	)
	cmd.SetSrcFile("mytest.go")
	cmd.SetIncludeFile(true)
	cmd.Run()
}
Output:

package x

import (
	"fmt"
	"strings"
)

func x() { fmt.Println("hello") }
// gomerge src: mytest.go

func y() { strings.Repeat(" ", 10) }

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Merge

func Merge(w io.Writer, dst, src []byte) error

Merge creates and runs a default merge between two go source expressions.

Types

type GoMerge

type GoMerge struct {
	// contains filtered or unexported fields
}

func New

func New(w io.Writer, dst, src []byte) *GoMerge

func (*GoMerge) Run

func (me *GoMerge) Run() error

func (*GoMerge) SetIncludeFile

func (me *GoMerge) SetIncludeFile(v bool)

func (*GoMerge) SetSrcFile

func (me *GoMerge) SetSrcFile(v string)

type GoSrc

type GoSrc struct {
	Header  string // docs before package
	Package string // package
	Imports string // imports
	Rest    string // rest of the content
}

func Parse

func Parse(src []byte) *GoSrc

Parse reads go file content into the different fields. It does not care if the code is proper or not, it only looks for the specific elements in the field order.

func (*GoSrc) String

func (s *GoSrc) String() string

Directories

Path Synopsis
cmd
gomerge
Command gomerge merges two or more go files, removing duplicate imports.
Command gomerge merges two or more go files, removing duplicate imports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL