Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building CLI apps with Ruby

Building CLI apps with Ruby

A presentation on Ruby CLI apps at Linux Weekend
https://gist.github.com/aziflaj/d4f82aaf05e8293c08ae79f9b30af35b

Aldo Ziflaj

March 26, 2017
Tweet

More Decks by Aldo Ziflaj

Other Decks in Programming

Transcript

  1. Two of the most famous products of Berkeley are LSD

    and Unix. I don’t think that this is a coincidence. Anonymous
  2. Elegant Weapon for a more Civilized Age $ # Kill

    every Google app $ ps aux | grep google | grep -v grep | awk '{ print $2 }' | xargs kill -15
  3. Elegant Weapon for a more Civilized Age $ # Kill

    every Google app $ ps aux | grep google | grep -v grep | awk '{ print $2 }' | xargs kill -15 ps: process status
  4. Elegant Weapon for a more Civilized Age $ # Kill

    every Google app $ ps aux | grep google | grep -v grep | awk '{ print $2 }' | xargs kill -15 ps: process status grep: globally search a regular expression and print
  5. Elegant Weapon for a more Civilized Age $ # Kill

    every Google app $ ps aux | grep google | grep -v grep | awk '{ print $2 }' | xargs kill -15 ps: process status grep: globally search a regular expression and print awk: Text processing & Data extraction
  6. Elegant Weapon for a more Civilized Age $ # Kill

    every Google app $ ps aux | grep google | grep -v grep | awk '{ print $2 }' | xargs kill -15 ps: process status grep: globally search a regular expression and print awk: Text processing & Data extraction kill: Save a .docx document
  7. Create the project $ mkdir dolittle && cd $_ $

    bundle init $ echo gem \'thor\' >> Gemfile $ bundle install $ touch dolittle
  8. #!/usr/bin/env ruby require 'thor' class Dolittle < Thor desc 'hello

    [GREETER]', 'adds a new task' def hello(greeter = 'World') puts "Hello #{greeter}" end end Dolittle.start(ARGV)
  9. def initialize(*args) super @file = File.open('todolist.dat', 'a+') end desc 'add

    TASK', 'adds a new task' def add(task) @file.puts task end
  10. desc 'done TASK', 'delete a task' def done(task_index) `sed -i

    '#{task_index}d' #{File.basename(@file)}` end