Skip to content

marcuwynu23/dan-cli

DAN CLI - Data Advanced Notation Command Line Tool

A Go implementation of the DAN (Data Advanced Notation) parser and encoder with a command-line interface.

Features

  • Parse DAN format - Convert DAN text to structured data
  • Encode to DAN - Convert structured data (JSON or DAN) to DAN format
  • Pretty-print - Format DAN files for better readability
  • JSON support - Convert between DAN and JSON formats

Installation

go build -o dan cmd/dan/main.go

Or install directly:

go install ./cmd/dan

Usage

Decode DAN

Convert DAN format to JSON or pretty-printed DAN:

# Decode from file
dan decode file.dan

# Decode from stdin
cat file.dan | dan decode

# Output as JSON
dan decode -json file.dan

Encode to DAN

Convert JSON or DAN to DAN format:

# Encode JSON file to DAN
dan encode -json file.json

# Encode DAN file (pretty-print)
dan encode file.dan

Pretty-print

Format DAN files:

dan pretty file.dan

DAN Format

DAN (Data Advanced Notation) is a human-readable data format that supports:

  • Key-value pairs: key: value
  • Nested objects: key { ... }
  • Tables: key: table(col1, col2) [ ... ]
  • Arrays: key: [value1, value2]
  • Comments: # comment or // comment
  • Data types: strings, numbers, booleans, arrays

Example

name: "John Doe"
age: 30
active: true
tags: ["developer", "go"]

address {
  street: "123 Main St"
  city: "New York"
  zip: 10001
}

users: table(name, age, email) [
  "Alice", 25, "alice@example.com"
  "Bob", 30, "bob@example.com"
]

Library Usage

You can also use the DAN library in your own Go programs:

package main

import (
    "fmt"

    "github.com/marcuwynu23/godan/lib"
)

func main() {
    // Decode DAN text
    data, err := lib.Decode(`name: "test"`)
    if err != nil {
        panic(err)
    }
    fmt.Println(data)

    // Encode to DAN
    obj := map[string]interface{}{
        "name": "test",
        "age": 30,
    }
    output := lib.Encode(obj)
    fmt.Println(output)
}

Testing

Parser tests run in the godan module (github.com/marcuwynu23/godan), checked out at ../dango in this monorepo:

go -C ../dango test ./...

Verbose and benchmarks:

go -C ../dango test ./... -v
go -C ../dango test ./... -bench=. -benchmem

From this directory you can also use make test, make test-verbose, and make bench.

Use go -C ../dango test ./... or make test to exercise the library the CLI depends on (github.com/marcuwynu23/godan/lib).

Project structure

dan-cli/
├── cmd/dan/main.go   # CLI entrypoint
├── examples/         # Sample .dan files
├── go.mod            # depends on github.com/marcuwynu23/godan/lib
└── README.md

Community

License

MIT

About

a command-line interface for DAN (Data Advanced Notation) parser and encoder

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors