# Command Line Arguments

**URL:** <https://forum.crystal-lang.org/t/command-line-arguments/2153>\
**Category:** Help & Support\
**Created:** [May 23, 2020, 2:06am UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153 "2020-05-23T02:06:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![glued2thefloor](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/glued2thefloor/32/839_2.png) [@glued2thefloor](https://forum.crystal-lang.org/u/glued2thefloor)\
**Post date:** [May 23, 2020, 2:06am UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153/1 "2020-05-23T02:06:06Z")

</div>

I’m having some trouble finding documentation of implementing command-line arguments. I found something called option\_parser, but did not find examples of it taking input from the user. I found other examples of taking user arguments with  
ARGV, but they had no parameters. I tried inserting ARGV into an example I had with option\_parser, but this and other attempts I made did not work:

```
 require "option_parser"
  
 string = "echo "
  
 OptionParser.parse do |parser|
    parser.banner = "Genric Banner"
  
    parser.on "-e", "--execute", "Execute commands" do
      ARGV
      exit
    end
    parser.on "-v", "--version", "Show version" do
      puts "version 1.0"
      exit
    end
    parser.on "-h", "--help", "Show help" do
      puts parser
      exit
    end
  end
  
  y = "#{string}#{ARGV}"
  
  Process.run(y, shell: true) do |proc|
    IO.copy(proc.output, STDOUT)
  end

```

I’m unsure of the best way to do this. If ARGV is needed, I’ll probably need to ask how to do with with multiple arguments. Any feedback appreciated.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [May 23, 2020, 2:08am UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153/2 "2020-05-23T02:08:39Z")

</div>

Using the example from [https://crystal-lang.org/api/master/OptionParser.html](https://crystal-lang.org/api/master/OptionParser.html).

```auto
crystal build app.cr
./app -h
./app --upcase -t Jim

```

---

<div class="post-metadata">

**Author:** ![glued2thefloor](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/glued2thefloor/32/839_2.png) [@glued2thefloor](https://forum.crystal-lang.org/u/glued2thefloor)\
**Post date:** [May 23, 2020, 2:15am UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153/3 "2020-05-23T02:15:02Z")

</div>

Interesting, I was taken to a part of that same wiki earlier, but not the OptionParser section. I must have been googling something wrong. This I can work with. Thank you.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [May 23, 2020, 2:17am UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153/4 "2020-05-23T02:17:31Z")

</div>

np. I’d also check out [https://crystal-lang.org/reference/getting\_started/cli.html](https://crystal-lang.org/reference/getting_started/cli.html) if you haven’t.

---

<div class="post-metadata">

**Author:** ![nico](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/nico/32/692_2.png) [@nico](https://forum.crystal-lang.org/u/nico)\
**Post date:** [May 23, 2020, 12:00pm UTC](https://forum.crystal-lang.org/t/command-line-arguments/2153/5 "2020-05-23T12:00:05Z")

</div>

Also 2 goods shards for handling CLI:

- [https://github.com/at-grandpa/clim](https://github.com/at-grandpa/clim)
- [https://github.com/jwaldrip/admiral.cr](https://github.com/jwaldrip/admiral.cr)

Support sub-commands and other handy features
