Commented commands package

This commit is contained in:
Ahsanul Haque 2014-12-12 00:05:02 +06:00
parent 9b04c27998
commit b11838da3f
2 changed files with 12 additions and 1 deletions

View file

@ -11,6 +11,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//Package commands defines and implements command-line commands and flags used by Hugo. Commands and flags are implemented using
//cobra.
package commands package commands
import ( import (
@ -36,7 +38,7 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
//var Config *hugolib.Config //HugoCmd is Hugo's root command. Every other command attached to HugoCmd is a child command to it.
var HugoCmd = &cobra.Command{ var HugoCmd = &cobra.Command{
Use: "hugo", Use: "hugo",
Short: "Hugo is a very fast static site generator", Short: "Hugo is a very fast static site generator",
@ -52,14 +54,17 @@ Complete documentation is available at http://gohugo.io`,
var hugoCmdV *cobra.Command var hugoCmdV *cobra.Command
//Flags that are to be added to commands.
var BuildWatch, Draft, Future, UglyUrls, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, NoTimes bool var BuildWatch, Draft, Future, UglyUrls, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, NoTimes bool
var Source, Destination, Theme, BaseUrl, CfgFile, LogFile string var Source, Destination, Theme, BaseUrl, CfgFile, LogFile string
//Execute adds all child commands to the root command HugoCmd and sets flags appropriately.
func Execute() { func Execute() {
AddCommands() AddCommands()
utils.StopOnErr(HugoCmd.Execute()) utils.StopOnErr(HugoCmd.Execute())
} }
//AddCommands adds child commands to the root command HugoCmd.
func AddCommands() { func AddCommands() {
HugoCmd.AddCommand(serverCmd) HugoCmd.AddCommand(serverCmd)
HugoCmd.AddCommand(version) HugoCmd.AddCommand(version)
@ -70,6 +75,7 @@ func AddCommands() {
HugoCmd.AddCommand(listCmd) HugoCmd.AddCommand(listCmd)
} }
//Initializes flags
func init() { func init() {
HugoCmd.PersistentFlags().BoolVarP(&Draft, "buildDrafts", "D", false, "include content marked as draft") HugoCmd.PersistentFlags().BoolVarP(&Draft, "buildDrafts", "D", false, "include content marked as draft")
HugoCmd.PersistentFlags().BoolVarP(&Future, "buildFuture", "F", false, "include content with datePublished in the future") HugoCmd.PersistentFlags().BoolVarP(&Future, "buildFuture", "F", false, "include content with datePublished in the future")
@ -92,6 +98,7 @@ func init() {
hugoCmdV = HugoCmd hugoCmdV = HugoCmd
} }
// InitializeConfig initializes a config file with sensible default configuration flags.
func InitializeConfig() { func InitializeConfig() {
viper.SetConfigFile(CfgFile) viper.SetConfigFile(CfgFile)
viper.AddConfigPath(Source) viper.AddConfigPath(Source)
@ -297,6 +304,7 @@ func buildSite(watching ...bool) (err error) {
return nil return nil
} }
//NewWatcher creates a new watcher to watch filesystem events.
func NewWatcher(port int) error { func NewWatcher(port int) error {
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
tweakLimit() tweakLimit()

View file

@ -72,6 +72,7 @@ as you see fit.
Run: NewTheme, Run: NewTheme,
} }
//NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) { func NewContent(cmd *cobra.Command, args []string) {
InitializeConfig() InitializeConfig()
@ -103,6 +104,7 @@ func NewContent(cmd *cobra.Command, args []string) {
} }
} }
// NewSite creates a new hugo site and initializes a structured Hugo directory.
func NewSite(cmd *cobra.Command, args []string) { func NewSite(cmd *cobra.Command, args []string) {
if len(args) < 1 { if len(args) < 1 {
cmd.Usage() cmd.Usage()
@ -132,6 +134,7 @@ func NewSite(cmd *cobra.Command, args []string) {
createConfig(createpath, configFormat) createConfig(createpath, configFormat)
} }
//NewTheme creates a new Hugo theme.
func NewTheme(cmd *cobra.Command, args []string) { func NewTheme(cmd *cobra.Command, args []string) {
InitializeConfig() InitializeConfig()