~srivathsan/blaze

6a4cf60eb927a1d985aba3ad941f849b7a887c9c — Srivathsan Murali 3 years ago 3cab436
remove new command from blaze
1 files changed, 2 insertions(+), 63 deletions(-)

M blaze.go
M blaze.go => blaze.go +2 -63
@@ 33,69 33,8 @@ func main() {
	}
}

func usageBlaze() {
	fmt.Printf("Usage: %s <command> [<args>]\n\n", os.Args[0])
	fmt.Println("  new     Add new pages to content folder")
	fmt.Println("  build   Build the site")
	os.Exit(1)
}

func run() error {
	if len(os.Args) < 2 {
		usageBlaze()
	}
	cmd := os.Args[1]
	args := append(os.Args[:1], os.Args[2:]...)
	switch cmd {
	case "new":
		return cmdNew(args)
	case "build":
		return cmdBuild(args)
	default:
		usageBlaze()
	}

	return nil
}

func cmdNew(args []string) error {
	opts, _, err := getopt.Getopts(args, "r:p:h")
	if err != nil {
		return err
	}
	var root, page string

	for _, opt := range opts {
		switch opt.Option {
		case 'r':
			root = opt.Value
		case 'p':
			page = opt.Value
		default:
			fmt.Printf("Usage %s %s:\n\n", os.Args[0], os.Args[1])
			fmt.Println("  -r    Root folder for static size (default: cwd)")
			fmt.Println("  -p    Page path relative to contents folder. (Required)")
			fmt.Println("  -h    Shows this message")
			os.Exit(1)
		}
	}

	blazeConfig, err := config.LoadConfig(root)
	if err != nil {
		log.Printf("Failed to load config: %s\n", err.Error())
		return err
	}

	if page == "" {
		fmt.Println("flag -p is required")
		os.Exit(1)
	}

	return builder.CreatePage(page, blazeConfig)
}

func cmdBuild(args []string) error {
	opts, _, err := getopt.Getopts(args, "dswhr:p:")
	opts, _, err := getopt.Getopts(os.Args, "dswhr:p:")
	if err != nil {
		return err
	}


@@ 119,7 58,7 @@ func cmdBuild(args []string) error {
		case 'w':
			useWatcher = true
		default:
			fmt.Printf("Usage %s %s:\n\n", os.Args[0], os.Args[1])
			fmt.Printf("Usage %s:\n\n", os.Args[0])
			fmt.Println("  -r    Root folder for static size (default: cwd)")
			fmt.Println("  -s    Serve the public folder")
			fmt.Println("  -d    Build draft pages")