# Example, just for fun

# Just tell anybody or the "world" hello
def "nur hello" [
    name: string = "world"  # The name to say hello to
] {
    print $"hello ($name)"
}

# Actual useful tasks

# Run cargo
def "nur cargo" [...args: string] {
    cargo ...$args
}

# Run cargo build
def "nur build" [...args: string] {
    cargo "build" ...$args
}

# Run cargo run
def "nur run" [...args: string] {
    cargo "run" ...$args
}

# Update version in Cargo.toml
def "nur version" [
    version: string
] {
    let parsed_version = $version | parse --regex '^(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9]+)(-rc(?P<rc>[0-9]+))?$'
    if ($parsed_version | is-empty) {
        error make { msg: "No valid version string provided" }
    }
    cargo set-version $version
}

# Publish to crates.io
def "nur publish" [] {
    cargo publish
}

# release
def "nur release" [
    --version: string
] {
    if ($version != null) {
        print $"Updating to version ($version)"
        nur version $version
        git add Cargo.toml Cargo.lock
        git commit -m $"Release v($version)"
        git tag $"v($version)"
    }
    print "Publishing to crates.io"
    nur publish
}
