first commit
This commit is contained in:
commit
d31f48788e
47
Calc.go
Normal file
47
Calc.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/Knetic/govaluate"
|
||||||
|
)
|
||||||
|
|
||||||
|
var exp string = ""
|
||||||
|
var ver string = ""
|
||||||
|
var vsn bool = false
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.BoolVar(&vsn, "v", false, "Show Program Version")
|
||||||
|
flag.StringVar(&exp, "e", "", "Evaluable Expression")
|
||||||
|
flag.Parse()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if vsn {
|
||||||
|
_ShowVersion()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if exp == "" {
|
||||||
|
flag.Usage()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
expression, err := govaluate.NewEvaluableExpression(exp)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[ERR] %v\r\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
result, err := expression.Evaluate(nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[ERR] %v\r\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Printf("Result=%v\r\n", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ShowVersion() {
|
||||||
|
fmt.Printf("%s\r\nAuthor: %s\r\nVersion: %s\r\n", os.Args[0], "TE / Vayne Tan", ver)
|
||||||
|
}
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module Calc
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/Knetic/govaluate v3.0.0+incompatible
|
Loading…
x
Reference in New Issue
Block a user