YAML.parse("./shard.yml")["homepage"].as_s? I think it’s also possible to install the shards shard and use its types via .from_yaml but this is simpler. Of if you want to stick with a shell command, could do like oq -i yaml '.homepage' shard.yml.
This is super inefficient because crystal eval needs to build the parser program on every compilation. macro run would be better because it caches the macro program.
However, there is no need to use a custom program for this in the first place. You can use an existing YAML parser tool like oq or yq.
Since the YAML format is pretty simple, some shell tools without syntax support could also get you there. For example:
grep -o '^homepage:[[:space:]]*.*' shard.yml | sed 's/^homepage:[[:space:]]*//'
This could even be simplified with GNU extensions:
Yes, crystal eval is inefficient, so using tools like oq, grep, or sed is a practical way.
Still, it’s a bit sad that Crystal doesn’t have a built-in way to read shard.yml at compile time.
Also, grep or sed may not work on Windows by default.
You can create a small shard for this. Returning everything at compile time with a nice API without depending on external tools. Just a run macro that populate a struct or some constants.