From 10bcaaaff3b75c80121b1b8a418200e63382e9c3 Mon Sep 17 00:00:00 2001 From: Rahul Tarak Date: Sat, 15 Jan 2022 04:23:38 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20versioning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli.go | 36 +++++++++++++++++++++++++++++++++-- internal/commands/create.go | 8 -------- internal/commands/prettier.go | 11 ++++++++++- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/cli.go b/cli.go index c8a2f28..6ecfd24 100644 --- a/cli.go +++ b/cli.go @@ -1,11 +1,19 @@ package main import ( + "fmt" "internal/commands" "github.com/urfave/cli/v2" ) +var ( + version = "dev" + commit = "none" + date = "unknown" + builtBy = "unknown" +) + func SetupCliApp() (cli.App, error) { cliCommands := []*cli.Command{ @@ -47,8 +55,14 @@ func SetupCliApp() (cli.App, error) { { Name: "prettier", Usage: "Will run pretty-quick", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "all", + Usage: "Will prettify all files instead of staged files", + }, + }, Action: func(c *cli.Context) error { - return commands.HandlePrettierCommand() + return commands.HandlePrettierCommand(c.Bool("all")) }, }, { @@ -64,6 +78,15 @@ func SetupCliApp() (cli.App, error) { return commands.HandleLintCommand(c.Bool("fix")) }, }, + { + Name: "version", + Usage: "Version of cli", + Aliases: []string{"v"}, + Action: func(c *cli.Context) error { + fmt.Printf("tsdev %s, commit %s, built at %s by %s", version, commit, date, builtBy) + return nil + }, + }, } app := &cli.App{ @@ -74,13 +97,22 @@ func SetupCliApp() (cli.App, error) { ArgsUsage: "Run a .ts file with zero config directly", Action: func(c *cli.Context) error { - return commands.HandleDefault(c.Bool("watch"), c.Args().Slice()) + if c.Bool("version") { + fmt.Printf("tsdev %s, commit %s, built at %s by %s", version, commit, date, builtBy) + return nil + } else { + return commands.HandleDefault(c.Bool("watch"), c.Args().Slice()) + } }, Flags: []cli.Flag{ &cli.BoolFlag{ Name: "watch", Usage: "Run in watch mode", }, + &cli.BoolFlag{ + Name: "version", + Aliases: []string{"v"}, + }, }, } diff --git a/internal/commands/create.go b/internal/commands/create.go index 7c312b2..b57dad4 100644 --- a/internal/commands/create.go +++ b/internal/commands/create.go @@ -116,14 +116,6 @@ func createDir(name string) error { return nil } -// Will clone skeleton template -func cloneTemplate(name string) error { - - // Download templates from releases and unzip them - - return nil -} - // Will generate package json func generatePackageJson(name string) { diff --git a/internal/commands/prettier.go b/internal/commands/prettier.go index c609074..c9dba2f 100644 --- a/internal/commands/prettier.go +++ b/internal/commands/prettier.go @@ -8,7 +8,16 @@ import ( "os" ) -func HandlePrettierCommand() error { +func handlePrettyAll() error { + + return nil +} + +func HandlePrettierCommand(allFlag bool) error { + + if allFlag { + return handlePrettyAll() + } if _, err := os.Stat(types.PRETTY_QUICK_PATH); errors.Is(err, os.ErrNotExist) {