# ArgParse visualization of argument type and default value

**URL:** https://discourse.julialang.org/t/argparse-visualization-of-argument-type-and-default-value/126284
**Category:** New to Julia
**Tags:** question, io
**Created:** [February 25, 2025, 11:12am UTC](https://discourse.julialang.org/t/argparse-visualization-of-argument-type-and-default-value/126284 "2025-02-25T11:12:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Oblomov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oblomov/32/211073_2.png) [@Oblomov](https://discourse.julialang.org/u/Oblomov)
#### Post date: [February 25, 2025, 11:12am UTC](https://discourse.julialang.org/t/argparse-visualization-of-argument-type-and-default-value/126284/1 "2025-02-25T11:12:56Z")

</div>

Hello all,

does anybody know if there is a way to customize the way `ArgParse` shows the default type and value for arguments where this is set? I’m particularly annoyed by the fact that e.g. for an `UInt` value the default is being shown in hexadecimal with all digits rather than in decimal:

> (type: UInt64, default: 0x0000000000000064)

I tried perusing the documentation, and there seems to be no way to customize this. The effect seems related to `ArgParse`’ `string_cmpact` function, that builds the string representation via `show(IOContext(..., :compact=>true), ...)`, which when applied to an `UInt` rather than an `Int` will switch to hex.

---

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [March 2, 2025, 6:33pm UTC](https://discourse.julialang.org/t/argparse-visualization-of-argument-type-and-default-value/126284/2 "2025-03-02T18:33:19Z")

</div>

Hi,

I don’t think there’s a nice way to achieve this. I suppose you could create a PR to add a field `default_string::String` to `ArgParseField`, which defaults to using `string_compact(default)` if `default` is set. In `gen_help_text` you’d then just use `default_str = mid * "default: " * arg.default_string`. I don’t see many situations where this would be useful, though.

If you only want change how all instances of a type get printed, you could create a wrapper type (e.g. `MyUInt`) which is basically `UInt`, except for `show`. I guess this would be a lot of work, although there might be some packages with useful macros.

If you’re comfortable with a bit of type piracy, the simplest approach would be to (re)define `string_compact`. For example,

```julia
using ArgParse

function ArgParse.string_compact(x::UInt)
	return string(x, base=10)
end

function parse_commandline()
    s = ArgParseSettings()

    @add_arg_table! s begin
        "--arg"
            arg_type = UInt
            default = 100
    end

    return parse_args(s)
end

parse_commandline()

```

in a file `ap.jl` yields

```julia
> julia ap.jl --help
usage: ap.jl [--arg ARG] [-h]

optional arguments:
  --arg ARG (type: UInt64, default: 100)
  -h, --help show this help message and exit

```

---

<div class="post-metadata">

### Author: ![Oblomov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oblomov/32/211073_2.png) [@Oblomov](https://discourse.julialang.org/u/Oblomov)
#### Post date: [March 3, 2025, 7:18am UTC](https://discourse.julialang.org/t/argparse-visualization-of-argument-type-and-default-value/126284/3 "2025-03-03T07:18:16Z")

</div>

Thanks for the feedback. The custom type sounds like a good idea. Provisionally, since we don’t need the full range of the `UInt` and we need to check that the given argument is (strictly) positive anyway, I’ve just turned it into a simple `Int`), but I’ll be looking into making it its own type.
