-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #41 from nicholaswilde/refactor-config
refactor config
- Loading branch information
Showing
13 changed files
with
394 additions
and
327 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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
**/testdata/*.md | ||
|
||
.cookdocs | ||
.cookdocs.yml | ||
.cookdocs.yaml | ||
|
||
/site | ||
/cook-docs | ||
/cmd/cook-docs/cook-docs | ||
|
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 |
---|---|---|
@@ -1,87 +1,89 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/aquilax/cooklang-go" | ||
"github.com/nicholaswilde/cook-docs/pkg/cook" | ||
"github.com/nicholaswilde/cook-docs/pkg/document" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func retrieveInfoAndPrintDocumentation(recipeSearchRoot string, recipePath string, templateFiles []string, waitGroup *sync.WaitGroup, dryRun bool) { | ||
defer waitGroup.Done() | ||
|
||
recipeInfo := cook.ParseRecipeInformation(recipePath) | ||
|
||
recipeData, err := cooklang.ParseFile(recipeInfo.RecipePath) | ||
|
||
if err != nil { | ||
log.Warnf("Error parsing file for recipe %s, skipping: %s", recipeInfo.RecipePath, err) | ||
return | ||
} | ||
|
||
recipeData = cook.MergeRecipeData(recipeInfo, recipeData) | ||
|
||
document.PrintDocumentation(recipeSearchRoot, recipeData, recipeInfo, templateFiles, dryRun) | ||
} | ||
|
||
func cookDocs(_ *cobra.Command, _ []string) { | ||
initializeCli() | ||
|
||
recipeSearchRoot := viper.GetString("recipe-search-root") | ||
|
||
var fullRecipeSearchRoot string | ||
if path.IsAbs(recipeSearchRoot) { | ||
fullRecipeSearchRoot = recipeSearchRoot | ||
} else { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
log.Warnf("Error getting working directory: %s", err) | ||
return | ||
} | ||
fullRecipeSearchRoot = path.Join(cwd, recipeSearchRoot) | ||
} | ||
|
||
recipePaths, err := cook.FindRecipePaths(fullRecipeSearchRoot) | ||
if err != nil { | ||
log.Errorf("Error finding recipe paths: %s", err) | ||
os.Exit(1) | ||
} | ||
log.Infof("Found recipes [%s]", strings.Join(recipePaths, ", ")) | ||
|
||
templateFiles := viper.GetStringSlice("template-files") | ||
log.Debugf("Rendering from optional template files [%s]", strings.Join(templateFiles, ", ")) | ||
|
||
dryRun := viper.GetBool("dry-run") | ||
waitGroup := sync.WaitGroup{} | ||
|
||
for _, r := range recipePaths { | ||
waitGroup.Add(1) | ||
|
||
// On dry runs all output goes to stdout, and so as to not jumble things, generate serially | ||
if dryRun { | ||
retrieveInfoAndPrintDocumentation(fullRecipeSearchRoot, r, templateFiles, &waitGroup, dryRun) | ||
} else { | ||
go retrieveInfoAndPrintDocumentation(fullRecipeSearchRoot, r, templateFiles, &waitGroup, dryRun) | ||
} | ||
} | ||
waitGroup.Wait() | ||
} | ||
|
||
func main() { | ||
command, err := newCookDocsCommand(cookDocs) | ||
if err != nil { | ||
log.Errorf("Failed to create the CLI commander: %s", err) | ||
os.Exit(1) | ||
} | ||
if err := command.Execute(); err != nil { | ||
log.Errorf("Failed to start the CLI: %s", err) | ||
os.Exit(1) | ||
} | ||
} | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/nicholaswilde/cook-docs/pkg/cook" | ||
"github.com/nicholaswilde/cook-docs/pkg/document" | ||
"github.com/nicholaswilde/cook-docs/pkg/types" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func retrieveInfoAndPrintDocumentation(recipePath string, waitGroup *sync.WaitGroup, config *types.Config) { | ||
defer waitGroup.Done() | ||
|
||
recipe, err := cook.ParseFile(recipePath, config) | ||
if err != nil { | ||
log.Warnf("Error parsing file for recipe %s, skipping: %s", recipePath, err) | ||
return | ||
} | ||
|
||
document.PrintDocumentation(recipe) | ||
} | ||
|
||
func GetFullSearchRoot(searchRoot string) (string, error) { | ||
var fullSearchRoot string | ||
if path.IsAbs(searchRoot) { | ||
fullSearchRoot = searchRoot | ||
} else { | ||
cwd, err := os.Getwd() | ||
if err != nil { | ||
return "", err | ||
} | ||
fullSearchRoot = path.Join(cwd, searchRoot) | ||
} | ||
return fullSearchRoot, nil | ||
} | ||
|
||
func cookDocs(_ *cobra.Command, _ []string) { | ||
var config types.Config | ||
viper.Unmarshal(&config) | ||
|
||
initializeCli(&config) | ||
|
||
fullSearchRoot, err := GetFullSearchRoot(config.RecipeSearchRoot) | ||
if err != nil { | ||
log.Warnf("Error getting working directory: %s", err) | ||
return | ||
} | ||
|
||
recipePaths, err := cook.FindRecipeFilePaths(fullSearchRoot) | ||
if err != nil { | ||
log.Errorf("Error finding recipe paths: %s", err) | ||
os.Exit(1) | ||
} | ||
log.Infof("Found recipes [%s]", strings.Join(recipePaths, ", ")) | ||
|
||
log.Debugf("Rendering from optional template files [%s]", strings.Join(config.TemplateFiles, ", ")) | ||
|
||
waitGroup := sync.WaitGroup{} | ||
|
||
for _, r := range recipePaths { | ||
waitGroup.Add(1) | ||
|
||
// On dry runs all output goes to stdout, and so as to not jumble things, generate serially | ||
if config.DryRun { | ||
retrieveInfoAndPrintDocumentation(r, &waitGroup, &config) | ||
} else { | ||
go retrieveInfoAndPrintDocumentation(r, &waitGroup, &config) | ||
} | ||
} | ||
waitGroup.Wait() | ||
} | ||
|
||
func main() { | ||
command, err := newCookDocsCommand(cookDocs) | ||
if err != nil { | ||
log.Errorf("Failed to create the CLI commander: %s", err) | ||
os.Exit(1) | ||
} | ||
if err := command.Execute(); err != nil { | ||
log.Errorf("Failed to start the CLI: %s", err) | ||
os.Exit(1) | ||
} | ||
} |
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
Oops, something went wrong.