Skip to content

Commit 9d39e48

Browse files
committed
feat: add cli version flag
1 parent b5709b8 commit 9d39e48

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

cmd/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ type Command struct {
2222
func Run() {
2323
opts := options.Run()
2424

25+
if opts.Version {
26+
fmt.Printf("Styler version %v\n", options.Version)
27+
return
28+
}
29+
2530
if opts.Create {
2631
options.Create()
2732
return

options/cli.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import (
55
)
66

77
type Options struct {
8-
Create bool
8+
Create bool
9+
Version bool
910
}
1011

1112
func Run() Options {
1213
var create = flag.Bool("create", false, "Create a config file")
14+
var version = flag.Bool("version", false, "Version of styler")
1315
flag.Parse()
1416

1517
return Options{
16-
Create: *create,
18+
Create: *create,
19+
Version: *version,
1720
}
1821
}

options/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
const configPath = ".styler"
1010

11-
const version = "0.0.2"
11+
const Version = "0.0.3"
1212

1313
type Media struct {
1414
MaxWidth string `json:"maxWidth"`
@@ -318,7 +318,7 @@ var colors = map[string]map[string]string{
318318

319319
func New() Config {
320320
return Config{
321-
Version: version,
321+
Version: Version,
322322
Pattern: "*.R|*.r|*.js|*.html",
323323
Directory: ".",
324324
Output: "style.min.css",
@@ -392,11 +392,11 @@ func (c *Config) check() {
392392
return
393393
}
394394

395-
if c.Version != version {
395+
if c.Version != Version {
396396
fmt.Printf(
397397
"[WARNING] Config version (%v) is not the same as the current version (%v).\n",
398398
c.Version,
399-
version,
399+
Version,
400400
)
401401
fmt.Printf("If you encounter errors, please update the config file with: style -create\n")
402402
return

0 commit comments

Comments
 (0)