go-imports-rename

command module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: MIT Imports: 17 Imported by: 0

README

go-imports-rename

Tool to change import paths

Important case

  • Important case is to append suffix to existing path, i.e. to grow gitlab.example.com/common/utils into gitlab.example.com/common/utils/v2

    use

    go-imports-rename 'gitlab.example.com/common/utils/ ++' 
    

    to grow gitlab.example.com/common/utils/package into gitlab.example.com/common/utils/v2/package

Usage examples

  • Simple usage. Please do not use it for import paths upgrade from version below 2. Use ++ operator instead.

    go-imports-rename 'github.com/rsz/ => github.com/rs/' 
    

    will list all possible import path changes with given prefix github.com/rsz/ in Go files in current directory and all its subdirectories. No saves will be done.

  • Use --save flag to commit these changes:

    go-imports-rename --save 'github.com/rsz/ => github.com/rs/' 
    
  • Use --root flag to diagnose or make changes in specific directory:

    go-imports-rename --root $GOPATH/src 'github.com/rsz/ => github.com/rs/' 
    

    Will diagnose changes in $GOPATH/src

  • There is a shortcut for the fresh v1.x.y ⇒ v2.α.β migrations:

    go-imports-rename 'github.com/user/project ++' 
    

    It is an equivalent for

    go-imports-rename 'github.com/user/project/ => github.com/user/project/v2/'
    

    In this case the utility takes care of paths and will not replace github.com/user/projectNext. Also, github.com/user/project/v2 won't change. You can also move from v2 to v3 in the same way

    go-imports-rename 'github.com/user/project/v2 ++'
    
  • You can jump through several migrations:

    go-imports-rename 'github.com/user/project += 5'
    

    It is an equivalent for

    go-imports-rename 'github.com/user/project/ => github.com/user/project/v6'
    
  • Use // operator to imports rename with regular expression

    go-imports-rename '^gen/(.*)$ // gitlab.example.com/common/schema/$1' 
    

    will diagnose possible gen/common and similar imports changes into gitlab.example.com/common/schema/common, etc

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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