Ruby Gem Command Line Tool

I am trying to create a command line . I use the bundler to create the gem and set the gem in place. He created the necessary directories. I was also able to verify that if I require my Gem, I can use the methods inside it. I am trying to get a part of the command line to work now and cannot seem to make it work. I want to be able to do something like

gemname command

Similar to how works:

rspec test/whatever.rb

Any help on how to execute through the command line would be great.

+4
source share
4 answers

, yourgem.gemspec:

`git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

bundle gem yourgem. , yourgem.gemspec . bin/ , , lib/.

- . gem , . , . , :

 bundle exec bin/your_exec

lib/, .

, , gem build yourgem.gemspec, gem install yourgem.gem .

+2

, , . , git ls-files -- bin/* script, .

, git ls-files , script.

+2

: http://robdodson.me/blog/2012/06/14/how-to-write-a-command-line-ruby-gem/ http://rubylearning.com/blog/2011/01/03/how-do-i-make-a-command-line-tool-in-ruby/

, , :

  • #!/usr/bin/env ruby ( /bin).
  • chmod +x filname,
  • ARGV[0] ARGV[0]
  • s.executables << 'your_file' gemspec
0

I understood this at least for my specific problem. I just need to call the bin command directly instead of this git ls loop. The top one works for the bottom for no reason.

spec.executables = ["toolshed"]

vs

spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

0
source

Source: https://habr.com/ru/post/1523624/


All Articles