← Back to Upcase

Need Help to build a command line tool with help of Ruby


(Pradeep Gupta) #1

I made a plan to build my own command line tool with Ruby, So first of it , I wants to build a script which format attached USB Drive, Sequence to solve problem are, System first detect attached USB drive then give us warning messege Like: “All data will be erased , Are you sure?” We will get this messege to our Terminal.

My approach: I will start with a script demo.rb with Shebang Line then do:

# chmod u+x demo.rb 
 ```

Then i have plan to use my own demo command so that i can use in this way:

````ruby
 # demo someoptions somearguments
```
At first i wants to use OptionParser library, Is there anyway i can start in more to achieve that? Like any clue or suggestions so i can start to write some code here?





(George Brocklehurst) #2

I recently gave a live coding talk about building command line tools, the video’s not available yet, but you can look through the code on GitHub. Each commit adds another feature or fixes another bug, and the commit messages give a brief explanation of why I took the approach I did: https://github.com/georgebrock/greeter/commits/master

That specific command line tool doesn’t involve any argument parsing, but the official documentation for OptionParser includes extensive examples.


(Noah Clark) #3

You might want to look Thor as a great way to structure your program and might solve this problem in a more conventional way.


(Jon Seidel) #4

there’s a really nice book at pragmatic programmer on writing command line programs: http://pragprog.com/book/dccar/build-awesome-command-line-applications-in-ruby


(Pradeep Gupta) #5

Thanks to answers, I got broad answers, Can you narrow down answer and provide me specific soultion to my problem, Now i wants to write a Ruby script which will detect attached USB drive and will format it, problem is that every time when we attached new USB drive it will assigned different name like sdb1 or sdb2 or sdb3 or many more, So what will be solution to detect exact name and then run format command?