Commit 93c3bd02 authored by Tamer Tas's avatar Tamer Tas
Browse files

Write documentation for exportes values, types and functions

parent fd140595
Loading
Loading
Loading
Loading
+26 −6
Original line number Diff line number Diff line
@@ -13,26 +13,46 @@ import (
)

const (
	// Name of the application
	AppName = "boilr"

	// Version of the application
	Version = "0.1.0"

	// Configuration Directory of the application
	ConfigDirPath = ".config/boilr"

	// Configuration File Name of the application
	ConfigFileName = "config.json"

	// Directory that contains the template registry
	TemplateDir = "templates"

	// Name of the file that contains the context values for the template
	ContextFileName = "project.json"

	// Name of the directory that contains the template files in a boilr template
	TemplateDirName = "template"

	// Name of the file that contains the metadata about the template saved in registry
	TemplateMetadataName = "__metadata.json"

	// Owner of the github repository
	GithubOwner = "tmrts"

	// Name of the github repository
	GithubRepo = "boilr"
)

// Configuration contains the values for needed for boilr to operate.
// These values can be overridden by the inclusion of a boilr.json
// file in the configuration directory.
var Configuration = struct {
	FilePath        string
	TemplateDirPath string
}{}

// TemplatePath returns the absolute path of a template given the name of the template.
func TemplatePath(name string) (string, error) {
	return filepath.Join(Configuration.TemplateDirPath, name), nil
}
+1 −0
Original line number Diff line number Diff line
@@ -3,5 +3,6 @@ package boilr
import "errors"

var (
	// Indicates that a template is already present in the local registry.
	ErrTemplateAlreadyExists = errors.New("boilr: project template already exists")
)
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import (
	"github.com/tmrts/boilr/pkg/util/validate"
)

// Delete contains the cli-command for deleting templates.
var Delete = &cli.Command{
	Use:   "delete <template-name>",
	Short: "Delete a project template from the template registry",
+8 −12
Original line number Diff line number Diff line
@@ -24,17 +24,15 @@ func downloadZip(URL, targetDir string) error {
	f, err := ioutil.TempFile("", "boilr-download")
	if err != nil {
		return err
	} else {
	}
	defer f.Close()
	defer os.RemoveAll(f.Name())
	}

	resp, err := http.Get(URL)
	if err != nil {
		return err
	} else {
		defer resp.Body.Close()
	}
	defer resp.Body.Close()

	if _, err := io.Copy(f, resp.Body); err != nil {
		return err
@@ -47,17 +45,15 @@ func downloadZip(URL, targetDir string) error {
	r, err := zip.OpenReader(f.Name())
	if err != nil {
		return err
	} else {
		defer r.Close()
	}
	defer r.Close()

	extractFile := func(f *zip.File, dest string) error {
		rc, err := f.Open()
		if err != nil {
			return err
		} else {
			defer rc.Close()
		}
		defer rc.Close()

		// splits the first token of f.Name since it's zip file name
		path := filepath.Join(dest, strings.SplitAfterN(f.Name, "/", 2)[1])
@@ -71,9 +67,8 @@ func downloadZip(URL, targetDir string) error {
			f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
			if err != nil {
				return err
			} else {
				defer f.Close()
			}
			defer f.Close()

			if _, err := io.Copy(f, rc); err != nil {
				return err
@@ -97,10 +92,11 @@ func downloadZip(URL, targetDir string) error {
	return nil
}

// FIXME Half-Updates leave messy templates
// Download contains the cli-command for downloading templates from github.
var Download = &cli.Command{
	Use:   "download <template-repo> <template-name>",
	Short: "Download a project template from a github repository to template registry",
	// FIXME Half-Updates leave messy templates
	Run: func(c *cli.Command, args []string) {
		MustValidateArgs(args, []validate.Argument{
			{"template-repo", validate.UnixPath},
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ package cmd

import cli "github.com/spf13/cobra"

// GetBoolFlag retrieves the named boolean command-line
// flag given the command that contains it.
func GetBoolFlag(c *cli.Command, name string) bool {
	return c.PersistentFlags().Lookup(name).Value.String() == "true"
}
Loading