Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d3c8d5f
feat: define and parse specs format
ascandone Jun 19, 2025
c9ea16c
quick and dirty prototype
ascandone Jun 19, 2025
ba269e5
prototype v2
ascandone Jun 27, 2025
83c1a4c
colored diff!
ascandone Jun 27, 2025
950a6ba
minor
ascandone Jun 27, 2025
9c1b45a
proto
ascandone Jun 27, 2025
1be2da9
impl better UI for balances
ascandone Jun 27, 2025
5d8b0cc
improve prettyprint function
ascandone Jul 1, 2025
198424d
improve pprint
ascandone Jul 1, 2025
12b890d
improve ui
ascandone Jul 1, 2025
7819d04
improve run cmd ui
ascandone Jul 1, 2025
b4d6e2c
improve UI
ascandone Jul 1, 2025
64f5579
refactor
ascandone Jul 1, 2025
0a3cd5c
edit col
ascandone Jul 1, 2025
405e92b
show files stats
ascandone Jul 1, 2025
40af597
improve schema
ascandone Jul 2, 2025
beab3c0
change field name
ascandone Jul 2, 2025
ee14f67
add col
ascandone Jul 2, 2025
e522cdd
add util
ascandone Jul 2, 2025
1bdebe2
add interactive mode mvp
ascandone Jul 2, 2025
b6444df
allow feature flags
ascandone Jul 2, 2025
2b032e5
refactor assertions
ascandone Jul 7, 2025
8fa7b2d
show failed assertion's name
ascandone Jul 8, 2025
6715517
better handling of panic
ascandone Jul 8, 2025
7788876
refactor
ascandone Jul 8, 2025
caef0cb
improve err
ascandone Jul 8, 2025
d8a7b48
test cmd flags
ascandone Jul 8, 2025
8704cd0
removed comments
ascandone Jul 8, 2025
2bfbc51
refactor
ascandone Jul 8, 2025
86bb85e
WIP broken
ascandone Jul 8, 2025
d9dc7be
fix assertions
ascandone Jul 8, 2025
8f649d8
fix newline
ascandone Jul 10, 2025
1136103
defined schema for specs format
ascandone Jul 10, 2025
dd247ef
improve description
ascandone Jul 10, 2025
542e2d5
change fields name
ascandone Jul 10, 2025
333de3e
change color
ascandone Jul 10, 2025
3da5fb4
fix schema
ascandone Jul 10, 2025
d2bcbef
add required field to schema
ascandone Jul 12, 2025
f4fdd84
update schema
ascandone Jul 12, 2025
437e49f
test: added example tests
ascandone Jul 12, 2025
3c4f49a
test: migrate next 10 tests to specs format
devin-ai-integration[bot] Jul 12, 2025
665db37
removed test
ascandone Jul 12, 2025
3c31ae3
test: migrate next 50 tests to specs format
devin-ai-integration[bot] Jul 12, 2025
4b1b84e
fixes
ascandone Jul 12, 2025
5205083
test: migrate additional tests to specs format
devin-ai-integration[bot] Jul 12, 2025
ae42f04
test: migrate arithmetic and oneof tests to specs format
devin-ai-integration[bot] Jul 12, 2025
0b911d3
test: migrate more advanced tests to specs format
devin-ai-integration[bot] Jul 12, 2025
1650c2e
test: migrate color/asset tests to specs format
devin-ai-integration[bot] Jul 12, 2025
e20fe26
test: migrate more color tests to specs format
devin-ai-integration[bot] Jul 12, 2025
cfa8249
test: migrate additional color tests to specs format
devin-ai-integration[bot] Jul 12, 2025
6333fa2
test: migrate final color tests and balance update tests
devin-ai-integration[bot] Jul 12, 2025
8df9421
test: migrate overdraft and negative balance tests to specs format
devin-ai-integration[bot] Jul 12, 2025
5ba9a15
test: migrate final overdraft tests to specs format
devin-ai-integration[bot] Jul 12, 2025
4f8ee36
fix
ascandone Jul 12, 2025
3b982f2
fixes
ascandone Jul 12, 2025
594b296
fix: correct zero-postings-destination test to match original exactly
devin-ai-integration[bot] Jul 12, 2025
1dce11b
fix: correct zero-postings test scripts to match original test functi…
devin-ai-integration[bot] Jul 12, 2025
1ed48ab
fix: correct zero-postings JSON specs to match original TestZeroPosti…
devin-ai-integration[bot] Jul 12, 2025
f482fa4
fix: correct balance test to match original TestBalance function exactly
devin-ai-integration[bot] Jul 12, 2025
67dc6fa
fix: correct fabricated balance test scripts to match original functi…
devin-ai-integration[bot] Jul 12, 2025
75753fb
fix: correct use-balance-twice test to match original TestUseBalanceT…
devin-ai-integration[bot] Jul 12, 2025
c660580
fix: correct ask-balance-twice test to match original TestAskBalanceT…
devin-ai-integration[bot] Jul 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ go 1.22.1
require (
github.com/antlr4-go/antlr/v4 v4.13.1
github.com/gkampitakis/go-snaps v0.5.4
github.com/sergi/go-diff v1.0.0
)

require gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand All @@ -57,7 +59,8 @@ golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
79 changes: 76 additions & 3 deletions internal/ansi/ansi.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,95 @@
package ansi

import "fmt"
import (
"fmt"
"strings"
)

const resetCol = "\033[0m"

func Compose(cols ...func(string) string) func(string) string {
return func(s string) string {
for _, mod := range cols {
s = mod(s)
}
return s
}
}

func replaceLast(s, oldStr, newStr string) string {
lastIndex := strings.LastIndex(s, oldStr)
if lastIndex == -1 {
return s
}
return s[:lastIndex] + newStr + s[lastIndex+len(oldStr):]
}

func col(s string, code int) string {
c := fmt.Sprintf("\033[%dm", code)
return c + s + resetCol
colorCode := fmt.Sprintf("\033[%dm", code)
// This trick should allow to stack colors (TODO test)
s = replaceLast(s, resetCol, resetCol+colorCode)
return colorCode + s + resetCol
}

func ColorRed(s string) string {
return col(s, 31)
}

func ColorWhite(s string) string {
return col(s, 37)
}

func ColorGreen(s string) string {
return col(s, 32)
}

func ColorYellow(s string) string {
return col(s, 33)
}

func ColorCyan(s string) string {
return col(s, 36)
}

func ColorLight(s string) string {
return col(s, 97) // Bright white → light
}

func ColorBrightBlack(s string) string {
return col(s, 90)
}

func ColorBrightRed(s string) string {
return col(s, 91)
}

func ColorBrightGreen(s string) string {
return col(s, 92)
}

func ColorBrightYellow(s string) string {
return col(s, 93)
}

// BG
func BgDark(s string) string {
return col(s, 100)
}

func BgRed(s string) string {
return col(s, 41)
}

func BgGreen(s string) string {
return col(s, 42)
}

// modifiers

func Bold(s string) string {
return col(s, 1)
}

func Underline(s string) string {
return col(s, 4)
}
1 change: 1 addition & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func Execute(options CliOptions) {

rootCmd.AddCommand(lspCmd)
rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(getTestCmd())
rootCmd.AddCommand(getRunCmd())

if err := rootCmd.Execute(); err != nil {
Expand Down
31 changes: 12 additions & 19 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"strings"

"github.com/formancehq/numscript/internal/ansi"
"github.com/formancehq/numscript/internal/flags"
"github.com/formancehq/numscript/internal/interpreter"
"github.com/formancehq/numscript/internal/parser"
Expand All @@ -21,7 +20,7 @@ const (
OutputFormatJson = "json"
)

type Args struct {
type runArgs struct {
VariablesOpt string
BalancesOpt string
MetaOpt string
Expand All @@ -38,7 +37,7 @@ type inputOpts struct {
Balances interpreter.Balances `json:"balances"`
}

func (o *inputOpts) fromRaw(opts Args) {
func (o *inputOpts) fromRaw(opts runArgs) {
if opts.RawOpt == "" {
return
}
Expand All @@ -49,7 +48,7 @@ func (o *inputOpts) fromRaw(opts Args) {
}
}

func (o *inputOpts) fromStdin(opts Args) {
func (o *inputOpts) fromStdin(opts runArgs) {
if !opts.StdinFlag {
return
}
Expand All @@ -65,7 +64,7 @@ func (o *inputOpts) fromStdin(opts Args) {
}
}

func (o *inputOpts) fromOptions(path string, opts Args) {
func (o *inputOpts) fromOptions(path string, opts runArgs) {
if path != "" {
numscriptContent, err := os.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -103,7 +102,7 @@ func (o *inputOpts) fromOptions(path string, opts Args) {
}
}

func run(path string, opts Args) {
func run(path string, opts runArgs) {
opt := inputOpts{
Variables: make(map[string]string),
Meta: make(interpreter.AccountsMetadata),
Expand Down Expand Up @@ -164,25 +163,19 @@ func showJson(result *interpreter.ExecutionResult) {
}

func showPretty(result *interpreter.ExecutionResult) {
fmt.Println(ansi.ColorCyan("Postings:"))
postingsJson, err := json.MarshalIndent(result.Postings, "", " ")
if err != nil {
panic(err)
}
fmt.Println(string(postingsJson))

fmt.Println()
fmt.Println("Postings:")
fmt.Println(interpreter.PrettyPrintPostings(result.Postings))

fmt.Println(ansi.ColorCyan("Meta:"))
txMetaJson, err := json.MarshalIndent(result.Metadata, "", " ")
if err != nil {
panic(err)
if len(result.Metadata) != 0 {
fmt.Println("Meta:")
fmt.Println(interpreter.PrettyPrintMeta(result.Metadata))
}
fmt.Println(string(txMetaJson))

}

func getRunCmd() *cobra.Command {
opts := Args{}
opts := runArgs{}

cmd := cobra.Command{
Use: "run",
Expand Down
Loading