gobuffalo / genny Goto Github PK
View Code? Open in Web Editor NEWA framework for writing modular generators
License: MIT License
A framework for writing modular generators
License: MIT License
genny v2 could be improved imho by making the API feel more like one is writing go code using the standard library instead of an abstraction of such. This issue serves as a collection of sorts for those API proposals:
packr
With the io/fs
package introduced in go 1.16 we can remove all usages of packr
and replace them with their new equivalents.
genny.Runner
should not change behavior after instantiationAll fields of genny.Runner
should be private to ensure they are only set during instantiation of the object and not modified afterwards. Provide a New function with options like WithLogger
, WithExecFn
, etc. to set those fields. WithDisk
can be used by gentest.NewRunner
to return a runner for testing together with a reference to the virtual disk for seeding.
type Runner struct {
logger LoggerInterface // Instead of a concrete type Logger should just be an interface
context context.Context
execFn func(*exec.Cmd) error
fileFn func(File) (File, error)
chdirFn func(string, func() error) error
deleteFn func(string) error
requestFn func(*http.Request, *http.Client) (*http.Response, error)
lookPathFn func(string) (string, error)
root string
disk *Disk
steps map[string]*Step
moot *sync.RWMutex
results Results
curGen *Generator
}
genny.Runner
should abstract usage of virtual / real filesThe disk object represents a virtual file system that is used in a dry run to simulate the actual file system. It should not be accessed from outside genny.Runner
to prevent the user from thinking that modifying the disk actually changes something on the hard drive when a wet runner is used. Instead most of it's functionality will be added to genny.Runner:
// replaces File. Create creates a new file the returned file is a proxy of either os.File or a virtual file
// mkdir and mkdirall behave like their os package equivalents or create directories on the virtual disk
func (r *Runner) Create(name string) (*File, error)
func (r *Runner) Mkdir(name string, perm os.FileMode) error
func (r *Runner) MkdirAll(path string, perm os.FileMode) error
// new method signature, runner remembers where it chdir'd to correctly access to the virtual disk after changing the directory
// it also changes back to the original directory when the runner finishes
func (r *Runner) Chdir(dir string) error
// replaces from FindFile. tries to open a file on disk or the virtual file system
func (r *Runner) Open(name string) (*File, error)
// renamed from delete to be more in line with the "os" package
func (r *Runner) Remove(name string) error
func (r *Runner) RemoveAll(path string) error
// updated method signature to be more in line with "net/http" package:
func (r *Runner) DoRequest(req *http.Request) (*http.Response, error)
func (r *Runner) DoRequestWithClient(c *http.Client, req *http.Request) (*http.Response, error)
// unchanged
func (r *Runner) Exec(cmd *exec.Cmd) error
func (r *Runner) FindStep(name string) (*Step, error)
func (r *Runner) LookPath(file string) (string, error)
func (r *Runner) ReplaceStep(name string, s *Step) error
func (r *Runner) Results() Results
func (r *Runner) Run() error
func (r *Runner) Steps() []*Step
func (r *Runner) With(g *Generator) error
func (r *Runner) WithFn(fn func() (*Generator, error)) error
func (r *Runner) WithGroup(gg *Group)
func (r *Runner) WithNew(g *Generator, err error) error
func (r *Runner) WithRun(fn RunFn)
func (r *Runner) WithStep(name string, step *Step) error
gentest
package updatesTo make it easier to setup a virtual filesystem in tests now gentest.NewRunner()
returns access to the internal disk of the runner that is used for testing:
func NewRunner() (*genny.Runner, *genny.Disk)
io/fs
interfacesDisk
should implement the following interfaces; Runner
should probably implement most of these interfaces too:
fs.FS{} // because it is a FS
fs.StatFS{} // allows to walk the Disk with fs.WalkDir
fs.GlobFS{} // to easily find all files matching a pattern
fs.ReadDirFS{} // equivalent of os.ReadDir; allows more efficient walking
fs.ReadFileFS{} // equivalent of os.ReadFile
fs.SubFS{} // allows the creation of sub-filesystems
Returned virtual files and directories should implement the io/fs
interfaces like their os
equivalents:
fs.File{}
fs.DirEntry{}
We may need to add other common types mapping in here:
genny/movinglater/attrs/attrs.go
Line 16 in 9033ae7
In order to be able to support Pop
What is a "generator" in the context of this framework? The word has several meanings, and the readme doesn't clearly explain it.
Hello,
this worked fine yesterday 23/12/2019 with (probably) genny version 0.4.1 )v.5.x is 9 hours old right now)
I have a Dockerfile that from golang:1.13.4 uses
go get github.com/gobuffalo/buffalo/buffalo
The command fails with the error
build github.com/gobuffalo/buffalo/buffalo: cannot load github.com/gobuffalo/genny/gogen/gomods: module github.com/gobuffalo/genny@latest found (v0.5.2), but does not contain package github.com/gobuffalo/genny/gogen/gomods
In go.mod I have no reference to genny,so I suppose it is a dependency of buffalo
To be ablle to install buffalo can I use something lie
git config --global --add url."github.com/gobuffalo/[email protected]".insteadOf "https://github.com/gobuffalo/genny@latest"
Thanks
docker run --entrypoin bash -it golang/1.13.4
go get github.com/gobuffalo/buffalo/buffalo
no errors
build github.com/gobuffalo/buffalo/buffalo: cannot load github.com/gobuffalo/genny/gogen/gomods: module github.com/gobuffalo/genny@latest found (v0.5.2), but does not contain package github.com/gobuffalo/genny/gogen/gomods
buffalo is not installed, so no "buffalo info"
Hey @fasmat,
I just figured out that current runners doesn't support fs.FS
, so this issue would be a great enhancement.
What I have in mind is a single NewRunner(fs.FS)
:
NewRunner(fstest.MapFS{})
NewRunner(os.DirFS("."))
That said DryRunner
and WetRunner
could be kept, but they will just call NewRunner
with the appropriate fs
.
What do you think ?
EDIT: seems like I went a little too fast, fs.FS
is only a readable interface, so it cannot be used by a runner. Maybe this will change in the future.
Originally posted by @tbruyelle in #43 (comment)
The issue here: markbates/safe#1 shows the problem, this tiny dependency is calling for go 1.22 but not actually using go 1.22 features, which is pulling go 1.22 as a transitive compile requirement. This is not great for a monorepo that has things not ready to move to 1.22.
First recommendation: remove this dep. It's a couple lines of go code.
Alternative recommendation: wait for this author to fix this issue and then depend on that version that doesn't have an unnecessary dependency on a bleeding edge version of the language
Hello,
this worked fine yesterday 23/12/2019 with (probably) version 0.4.1 )v.5.x is 9 hours old right now)
I have a Dockerfile that from golang:1.13.4 uses
go get -u github.com/gobuffalo/buffalo/buffalo
The command fails with the error
build github.com/gobuffalo/buffalo/buffalo: cannot load github.com/gobuffalo/genny/gogen/gomods: module github.com/gobuffalo/genny@latest found (v0.5.2), but does not contain package github.com/gobuffalo/genny/gogen/gomods
In go.mod I have no reference to genny,so I suppose it is a dependency of buffalo
To be ablle to install buffalo can I use something lie
git config --global --add url."github.com/gobuffalo/[email protected]".insteadOf "https://github.com/gobuffalo/genny@latest"
Thanks
When running go get -v github.com/gobuffalo/pop/...
v4.7.2+incompatible the installation fails on the following lines
# github.com/gobuffalo/gogen/gomods
/go/src/github.com/gobuffalo/gogen/gomods/init.go:61:24: undefined: genny.GoBin
/go/src/github.com/gobuffalo/gogen/gomods/tidy.go:17:24: undefined: genny.GoBin
looking at the above lines of code gomods/init.go (https://github.com/gobuffalo/gogen/blob/v0.1.0/gomods/init.go#L61) and tidy.go (https://github.com/gobuffalo/gogen/blob/v0.1.0/gomods/tidy.go#L17) the are both calling genny.GoBin which is a non existent function.
Is there workaround or fix for this issue. This is causing problems with getting local environments and dev environments up and running for my organization
Kind regards
Tom Mitic
Hi, I found the code below generates so many files under the /tmp
but they are not removed after the build (in fact, buffalo dev
).
Also, I saw a comment something like "virtual file" and "virtual disk", and comment for Disk.Find()
said, it tries to find a file from virtual disk but if the file does not exist, then check for a real filesystem. Are they the physical files as a backup for this purpose? (or just remained old code?)
genny/movinglater/gotools/parsed_file.go
Lines 66 to 75 in 849d2c9
When calling
genny/movinglater/attrs/parse.go
Line 33 in 9033ae7
It allows to have duplicated attributes, when using this to generate code usually the plugin will need to validate this.
I wonder if we should keep the first of the same name we receive there.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.