-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from jmattheis/config
Config
- Loading branch information
Showing
233 changed files
with
5,945 additions
and
4,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,9 @@ do is create an interface and execute goverter. The project is meant as | |
alternative to [jinzhu/copier](https://github.com/jinzhu/copier) that doesn't | ||
use reflection. | ||
|
||
[Installation](https://goverter.jmattheis.de/#/install) ᛫ [Conversion Docs](https://goverter.jmattheis.de/#/conversion/) | ||
[Installation](https://goverter.jmattheis.de/#/install) ᛫ | ||
[CLI](https://goverter.jmattheis.de/#/cli) ᛫ | ||
[Config](https://goverter.jmattheis.de/#/config/) | ||
|
||
## Features | ||
|
||
|
@@ -37,12 +39,12 @@ use reflection. | |
- [Deep copies](https://en.wikipedia.org/wiki/Object_copying#Deep_copy) per | ||
default and supports [shallow | ||
copying](https://en.wikipedia.org/wiki/Object_copying#Shallow_copy) | ||
- **Customizable**: [You can implement custom converter methods](https://goverter.jmattheis.de/#/conversion/custom) | ||
- [Clear errors when generating the conversion methods](https://goverter.jmattheis.de/#/conversion/?id=error-early) if | ||
- **Customizable**: [You can implement custom converter methods](https://goverter.jmattheis.de/#/config/extend) | ||
- [Clear errors when generating the conversion methods](https://goverter.jmattheis.de/#/generation?id=error-early) if | ||
- the target struct has unmapped fields | ||
- types cannot be converted without losing information | ||
|
||
## Usage | ||
## Getting Started | ||
|
||
1. Ensure your `go version` is 1.16 or above | ||
|
||
|
@@ -52,7 +54,8 @@ use reflection. | |
$ go mod init module-name | ||
``` | ||
|
||
1. Create your converter interface and mark it with a comment containing `goverter:converter` | ||
1. Create your converter interface and mark it with a comment containing | ||
[`goverter:converter`](https://goverter.jmattheis.de/#/config/converter) | ||
|
||
`input.go` | ||
|
||
|
@@ -82,15 +85,16 @@ use reflection. | |
} | ||
``` | ||
|
||
See [Conversion](https://goverter.jmattheis.de/#/conversion/) for more information. | ||
See [Configuration](https://goverter.jmattheis.de/#/config) for more information. | ||
|
||
1. Run `goverter`: | ||
|
||
```bash | ||
$ go run github.com/jmattheis/goverter/cmd/[email protected] ./ | ||
``` | ||
|
||
See [Installation](https://goverter.jmattheis.de/#/install) for more information. | ||
See [Installation](https://goverter.jmattheis.de/#/install) and | ||
[CLI](https://goverter.jmattheis.de/#/cli) for more information. | ||
|
||
1. goverter created a file at `./generated/generated.go`, it may look like this: | ||
|
||
|
@@ -119,6 +123,8 @@ use reflection. | |
} | ||
``` | ||
See [Generation](https://goverter.jmattheis.de/#/generation) for more information. | ||
## Versioning | ||
goverter uses [SemVer](http://semver.org/) for versioning the cli. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package cli | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/jmattheis/goverter" | ||
"github.com/jmattheis/goverter/config" | ||
) | ||
|
||
type Strings []string | ||
|
||
func (s Strings) String() string { | ||
return fmt.Sprint([]string(s)) | ||
} | ||
|
||
func (s *Strings) Set(value string) error { | ||
*s = append(*s, value) | ||
return nil | ||
} | ||
|
||
func Parse(args []string) (*goverter.GenerateConfig, error) { | ||
switch len(args) { | ||
case 0: | ||
return nil, usage("unknown") | ||
case 1: | ||
return nil, usageErr("missing command: ", args[0]) | ||
default: | ||
if args[1] != "gen" { | ||
return nil, usageErr("unknown command: "+args[1], args[0]) | ||
} | ||
} | ||
|
||
fs := flag.NewFlagSet(args[0], flag.ContinueOnError) | ||
fs.Usage = func() { | ||
// fmt.Println(usage(args[0])) | ||
} | ||
|
||
var global Strings | ||
fs.Var(&global, "global", "add ") | ||
fs.Var(&global, "g", "add ") | ||
|
||
if err := fs.Parse(args[2:]); err != nil { | ||
return nil, usageErr(err.Error(), args[0]) | ||
} | ||
patterns := fs.Args() | ||
|
||
if len(patterns) == 0 { | ||
return nil, usageErr("missing PATTERN", args[0]) | ||
} | ||
|
||
c := goverter.GenerateConfig{ | ||
PackagePatterns: patterns, | ||
Global: config.RawLines{ | ||
Lines: global, | ||
Location: "command line (-g, -global)", | ||
}, | ||
} | ||
|
||
return &c, nil | ||
} | ||
|
||
func usageErr(err, cmd string) error { | ||
return fmt.Errorf("Error: %s\n%s", err, usage(cmd)) | ||
} | ||
|
||
func usage(cmd string) error { | ||
return fmt.Errorf(`Usage: | ||
%s gen [OPTIONS] PACKAGE... | ||
PACKAGE(s): | ||
Define the import paths goverter will use to search for converter interfaces. | ||
You can define multiple packages and use the special ... golang pattern to | ||
select multiple packages. See $ go help packages | ||
OPTIONS: | ||
-g [value], -global [value]: | ||
apply settings to all defined converters. For a list of available | ||
settings see: https://goverter.jmattheis.de/#/config/ | ||
-h, --help: | ||
display this help page | ||
Examples: | ||
%s gen ./example/simple ./example/complex | ||
%s gen ./example/... | ||
%s gen github.com/jmattheis/goverter/example/simple | ||
%s gen -g 'ignoreMissing no' -g 'skipCopySameType' ./simple | ||
Documentation: | ||
Full documentation is available here: https://goverter.jmattheis.de`, cmd, cmd, cmd, cmd, cmd) | ||
} |
Oops, something went wrong.