Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] YAML with template #2

Closed
10 of 35 tasks
at15 opened this issue Jan 6, 2017 · 3 comments
Closed
10 of 35 tasks

[config] YAML with template #2

at15 opened this issue Jan 6, 2017 · 3 comments
Assignees
Milestone

Comments

@at15
Copy link
Member

at15 commented Jan 6, 2017

Transferred from: dyweb/Ayi#65
Related issues: embed script language dyweb/Ayi#51, xephon-b config xephonhq/xephon-b#6, runner command config dyweb/Ayi#63

TODO

Get methods

Set method

  • Set
  • SetDefault
    • fall back to default data when parsed data does not have the wanted key
    • SetDefaultVar?

Load file

  • load from multiple locations and merge in order (just shallow merge, may support deep merge in the future?)
  • keep the path of loaded config files for debugging
  • allow strict and loose mode, if one file failed to parse, either we revert what's in it and just use what we got or we panic
  • traverse all the way back to /? like npm ?? (I saw some program traverse parent folders to find the nearest match, just could find one for now, maybe git?)

Legacy

TODO

  • specification
    • merge the example from runner
  • summarize the related libraries, the comments in these related issues all have some useful/inspiration libraries
  • write the test cast based on spec
  • implementation (need to divide into several stages)

Won't fix

we no longer use pongo2, so they are all fixed ....

@at15 at15 self-assigned this Jan 6, 2017
@at15 at15 added this to the 0.0.1 milestone Jan 7, 2017
@at15 at15 changed the title [config] Use template enabled YAML [config] YAML with template Mar 28, 2017
at15 added a commit that referenced this issue Mar 28, 2017
- NOTE: didn't test it, since we don't have getter functions like viper
  yet.
- Add `util` package for things that is handy but can not be grouped
  into a specific package, like get environment variables as
map[string]string
at15 added a commit that referenced this issue Mar 28, 2017
- previously, the second render is done regardless of current document
  has vars or not.
- add test for environment variables
- use 4 space for tab in golang file, this would avoid the yaml can't
  parse tab problem when writting test
- pongo render false to False, which is ok for Yaml, since it is very
  tolerant on the format of boolean values
@at15
Copy link
Member Author

at15 commented Mar 28, 2017

Found viper complains about go-yaml as well

// mergeMaps merges two maps. The itgt parameter is for handling go-yaml's
// insistence on parsing nested structures as map[interface{}]interface{}
// instead of using a string as the key for nest structures beyond one level
// deep. Both map types are supported as there is a go-yaml fork that uses
// map[string]interface{} instead.

I think it would be a good idea to write a new yaml parser for golang now

  • support multiple documents
  • stream? encode, decode
  • keep the order of objects as the appears in file (a.k.a have an ordered map)
  • decode to struct, like JSON unmarshal

at15 added a commit that referenced this issue Mar 28, 2017
- similar to https://github.com/spf13/cast
- need to use cast when working on config #2
  - [ ] I am still not sure if go-yaml is still using
    map[interface{}]interface{} for nested levels although based on previous comments, using map[string]interface{} won't work
at15 added a commit that referenced this issue Mar 28, 2017
- add util function to merge two map[string]interface{}
- add ParseSingleDocumentBytes and call it in ParseMultipleDocumentBytes
at15 added a commit that referenced this issue Mar 30, 2017
- keys inside `vars` are merged while other top level keys are merged
  inside directly, i.e. `vars: a:1  db:jack --- vars: b:1 db: marry`
would result in `var: a:1 b:1 db: marry`
at15 added a commit that referenced this issue Mar 30, 2017
- Get and GetOrDefault don't return error when the key does not exists,
  and default is helpful in some cases, though I think it's better to
set default values globally instead of put it when you read the config
@at15
Copy link
Member Author

at15 commented Jul 9, 2017

now I am considering using https://golang.org/pkg/text/template instead of pong2 because we don't need that much feature, though the golang syntax is a little bit strange ....

at15 added a commit that referenced this issue Jul 9, 2017
- for #2, we may not need that much feature on pongo2
- the main drawback of golang's built in template is its syntax is quite strange
- golang's template does support remove new line, though it would also trim tab
@at15 at15 modified the milestones: 0.0.2, 0.0.1 Jul 10, 2017
@at15 at15 modified the milestones: 0.0.2, 0.0.3 Sep 16, 2017
@at15
Copy link
Member Author

at15 commented Dec 28, 2017

so current version is using go's template, and has function to get environment variables, it is rendered twice to make use of variables declared in current file, it supports multiple yaml in same document (by split before unmarshal), also we no longer have so many getter and setter, we chose to unmarshal it into a go struct, which provides usage and type safety.

We may change to a DSL, like https://github.com/dhall-lang/dhall-lang, but that would be another story, sorry didn't have a release for config (patpat config) .... there is no semver in all projects where I am the only active developer and user ....

@at15 at15 closed this as completed Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant