# How to programmatically access documentation for fields of a composite type?

**URL:** <https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160>\
**Category:** General Usage\
**Created:** [January 27, 2019, 8:53pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160 "2019-01-27T20:53:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [January 27, 2019, 8:53pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/1 "2019-01-27T20:53:59Z")

</div>

Assuming code like this:

```julia
"This is a struct"
struct Bla
    "it has a field"
   a_field
end

bla = Bla(42)

```

How do I access the documentation of Bla.a\_field **from within a program** (I know how to get it at the REPL)? I can use the functions in `Base.Docs` (e.g. `@doc`) to access the doc string for `Bla`, but I haven’t found a way to do it for `Bla.a_field`.

For context: I want to automatically generate command line options from a `Parameters` object, using the documentation of the fields of the object to document the command line options.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 27, 2019, 9:00pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/2 "2019-01-27T21:00:02Z")

</div>

`REPL.fielddoc`, in action: [Parameters.jl/runtests.jl at 870131fa4114af141b4c40d8275259e5d19e444b · mauro3/Parameters.jl · GitHub](https://github.com/mauro3/Parameters.jl/blob/870131fa4114af141b4c40d8275259e5d19e444b/test/runtests.jl#L34)

Note sure whether this is the best way though.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [January 27, 2019, 9:09pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/3 "2019-01-27T21:09:30Z")

</div>

```julia
julia> foreach(f -> print("$f -- $(REPL.fielddoc(Bla, f))"), fieldnames(Bla))

a_field -- it has a field

```

---

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [January 27, 2019, 11:38pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/4 "2019-01-27T23:38:34Z")

</div>

Thanks, that solves my problem. That said, this solution is a lot of things, but definitely not pretty… If this is indeed the only way to access that information maybe I should file a bug report.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [January 28, 2019, 10:40am UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/5 "2019-01-28T10:40:55Z")

</div>

It doesn’t look like a bug to me, nor particularly ugly. Possibly it could be made more easily available in `Docs` instead of `REPL` (if it isn’t already). What do you consider problematic about it, and what would you suggest to improve it?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 28, 2019, 1:17pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/6 "2019-01-28T13:17:34Z")

</div>

Yep, that it is in REPL.

---

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [January 28, 2019, 2:58pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/7 "2019-01-28T14:58:39Z")

</div>

I agree, you shouldn’t have to go through REPL to access parts of the documentation. Plus Docs.@doc should be able to find _all_ documentation.

---

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [January 29, 2019, 6:17pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/8 "2019-01-29T18:17:55Z")

</div>

For reference, mauro’s (open) bug report from May last year:

[https://github.com/JuliaLang/julia/issues/27092](https://github.com/JuliaLang/julia/issues/27092)

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [January 29, 2019, 7:53pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/9 "2019-01-29T19:53:43Z")

</div>

> [@mhinsch](#):
>
> If this is indeed the only way to access that information maybe I should file a bug report / … / you shouldn’t have to go through REPL to access parts of the documentation. Plus Docs.@doc should be able to find _all_ documentation.

It’s not the only way, and you don’t have to go through `REPL`, you can get it from `Docs.meta`, although it’s not as nicely packaged as `fielddoc`. As for `@doc`, yes I agree it’d be nice, although I would call that a “missing feature”, not a “bug”. Marking words perhaps, but many programmers are quite sensitive to that distinction 🙂

---

<div class="post-metadata">

**Author:** ![mhinsch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mhinsch/32/26676_2.png) [@mhinsch](https://discourse.julialang.org/u/mhinsch)\
**Post date:** [January 29, 2019, 10:30pm UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/10 "2019-01-29T22:30:36Z")

</div>

> It’s not the only way, and you don’t have to go through `REPL` , you can get it from `Docs.meta`

And then someone decides to change the internal representation of the meta data and my code stops working. There’s a reason for stable, easily accessible APIs.

In any case, the issue has been known for a year, so apart from fixing it myself there’s really not much to do about it right now.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 30, 2019, 7:54am UTC](https://discourse.julialang.org/t/how-to-programmatically-access-documentation-for-fields-of-a-composite-type/20160/11 "2019-01-30T07:54:40Z")

</div>

> [@mhinsch](#):
>
> fixing it myself

Precisely 😉 Most issues get fixed by people who are most bothered by them.
