Commit 134e7fc9 authored by Hugo Moreau's avatar Hugo Moreau
Browse files

Config file: new tool generating config

In order to have a simplier tool, we now generate a config file in order
to re-use formulae.

 * main.go,
   tools/config.go : Modified.
parent f2828baa
......@@ -630,8 +630,15 @@ func main() {
}
defer f.Close()
var configJson []byte
if len(flag.Args()) >= 2 {
configJson = tools.GenerateSimpleConfig(flag.Args()[1])
} else {
configJson = tools.GenerateEmptyConfig()
}
if *formulae != "" {
*ignorefunc = tools.Formulae(flag.Args()[0], *formulae)
configJson = tools.GenerateConfig(*formulae)
}
if *ignorefunc != "" {
......@@ -721,6 +728,10 @@ func main() {
copyFile(from, to, data)
}
if err = ioutil.WriteFile(path.Join(*output, "config.json"), configJson, 0644); err != nil {
panic(err)
}
transpile_time := time.Since(start)
start = time.Now()
......
package tools
import (
"bufio"
"encoding/json"
"fmt"
"os"
)
type Config struct {
Formulae []string `json:"formulae"`
}
func GenerateConfig(formulaeFile string) []byte {
config := &Config{
Formulae: []string{},
}
input, err := os.Open(formulaeFile)
if err != nil {
fmt.Println(os.Stderr, err)
os.Exit(2)
}
scanner := bufio.NewScanner(input)
for scanner.Scan() {
config.Formulae = append(config.Formulae, scanner.Text())
}
var configJson []byte
if configJson, err = json.Marshal(config); err != nil {
panic(err)
}
return configJson
}
func GenerateSimpleConfig(formula string) []byte {
config := &Config{
Formulae: []string{formula},
}
var configJson []byte
var err error
if configJson, err = json.Marshal(config); err != nil {
panic(err)
}
return configJson
}
func GenerateEmptyConfig() []byte {
config := &Config{
Formulae: []string{},
}
var configJson []byte
var err error
if configJson, err = json.Marshal(config); err != nil {
panic(err)
}
return configJson
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment