-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cli cmd:public which collects html template files into single pub…
…lic directory while preserving the path. read template files embedded binary set by fir.WithEmbedFS
- Loading branch information
Showing
4 changed files
with
266 additions
and
113 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/adnaan/fir" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
inDir string | ||
outDir string | ||
extensions []string | ||
) | ||
|
||
// publicCmd represents the public command | ||
var publicCmd = &cobra.Command{ | ||
Use: "public", | ||
Short: "Generates the public folder containing the html files", | ||
Long: `The public command generates a public folder containing the html files in the project. | ||
It preserves the paths of the html files enabling a flexible project structure. The generated public directory | ||
can be embedded in the binary as is.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var opts []fir.PublicOption | ||
if inDir != "" { | ||
opts = append(opts, fir.InDir(inDir)) | ||
} | ||
|
||
if outDir != "" { | ||
opts = append(opts, fir.OutDir(outDir)) | ||
} | ||
|
||
if len(extensions) != 0 { | ||
opts = append(opts, fir.Extensions(extensions)) | ||
} | ||
|
||
if err := fir.GeneratePublic(opts...); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(publicCmd) | ||
publicCmd.Flags().StringVarP(&inDir, "in", "i", "", "path to input directory which contains the html template files") | ||
publicCmd.Flags().StringVarP(&outDir, "out", "o", "", "path to output directory") | ||
publicCmd.Flags().StringSliceVarP(&extensions, "extensions", "x", nil, "comma separated list of template exatensions e.g. .html,.tmpl") | ||
} |
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
Oops, something went wrong.