Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
= Methadone - kick the bash habit and start your command line apps off right
Author:: Dave Copeland (mailto:davetron5000 at g mail dot com) Copyright:: Copyright (c) 2011 by Dave Copeland License:: Distributes under the Apache License, see LICENSE.txt in the source distro
{}[http://travis-ci.org/davetron5000/methadone]
A smattering of tools to make your command-line apps easily awesome; kick the bash habit without sacrificing any of the power.
The goal of this project is to make it as easy as possible to write awesome and powerful command-line applications.
Toward that end, this gem provides:
== Tutorial
This tutorial is somewhat outdated, but generally still applies
{Tutorial for your iPad}[http://itunes.apple.com/us/book/kick-bash-habit-ruby-methadone/id515825242?ls=1] - This is a free iBooks interactive ebook that contains a step-by-step tutorial on making an awesome app with Methadone, including screencasts.
== Links
== Platforms
This library only supports the latest versions of Ruby. JRuby support has been too difficult to keep up with, though the library should work for JRuby.
See the {Travis config file}[./.travis.yml] for specifics.
== Bootstrapping a new CLI App
The +methadone+ command-line app will bootstrap a new command-line app, setting up a proper gem structure, unit tests, and integration tests.
It assumes you are using a standard Ruby development environment, which includes:
(Note that apps powered by this gem have no particular runtime dependencies as classes this gem provides depend only on the standard library)
$ methadone --help
Usage: methadone [options] app_name
Kick the bash habit by bootstrapping your Ruby command-line apps
v2.0.0
Options:
-h, --help Show command line help
--force Overwrite files if they exist
--[no-]readme [Do not ]produce a README file
--rspec Generate RSpec unit tests instead of Test::Unit
-l, --license LICENSE Specify the license for your project
(mit|apache|gplv2|gplv3|custom|NONE)
--log-level LEVEL Set the logging level
(debug|info|warn|error|fatal)
(Default: info)
--version Show help/version info
Arguments:
app_name
Name of your app, which is used for the gem name and executable name
Usage: methadone [options] app_name
--force Overwrite files if they exist
$ methadone myapp -l mit
$ cd myapp
$ bundle install
...
$ bundle exec rake
Started
.
Finished in 0.000499 seconds.
-----------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------
2004.01 tests/s, 2004.01 assertions/s
Started
.
Finished in 0.298281 seconds.
-----------------------------------------------------------------------------------------
1 tests, 8 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------
3.35 tests/s, 26.82 assertions/s
$ cat test/integration/test_cli.rb
require "methadone/test/base_integration_test"
class TestSomething < Methadone::BaseIntegrationTest
def test_truth
stdout,stderr,results = run_app("myapp","--help")
assert_banner(stdout, "myapp", takes_options: true, takes_arguments: false)
assert_option(stdout,"-h", "--help")
assert_option(stdout,"--version")
assert_oneline_summary(stdout)
end
end
Basically, this sets you up with all the boilerplate that you should be using to write a command-line app. Specifically, you get:
== DSL for your bin file
A canonical OptionParser-driven app has a few problems with it structurally that Methadone can solve:
Methadone provides Methadone::Main to help make a clean and easy-to-maintain bin file. See the {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/Main.html] for an example, and see {my blog}[http://www.naildrivin5.com/blog/2011/12/19/methadone-the-awesome-cli-library.html] on the derivation of this module.
== Wrapper for running external commands with good logging
While backtick and %x[] are nice for compact, bash-like scripting, they have some failings:
Enter Methadone::SH
sh "cp foo.txt /tmp"
# => logs command at DEBUG level
# if the command exited zero:
# logs the standard output at DEBUG
# logs the standard error at WARN
# if the command exited nonzero:
# logs the standard output at INFO
# logs the standard error at WARN
# returns the exit code for your examination
#
# there's a LOT MORE
See the {rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/SH.html] for more detailed examples and usage.
This isn't a replacement for Open3 or ChildProcess, but a way to easily "do the right thing" for most cases.
== Zero-Config Logging
Chances are, your code is littered with STDERR.puts on a good day, and nothing on a bad day. You probably also have a bunch of debug puts calls that you have commented out. Logging is extremely helpful in understanding how your app is behaving (or how it behaved in the past). Logging can be a pain to set up, and can also make it hard to give the user at the command-prompt a good experience.
Methadone::CLILogger is designed to handle this. It's a proper subclass of Ruby's built-in Logger with a few enhancements:
See {CLILogger's rdoc}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogger.html] and then {CLILogging's}[http://davetron5000.github.com/methadone/rdoc/classes/Methadone/CLILogging.html] for more.
Currently, there are classes that assist in directing output logger-style to the right place; basically ensuring that errors go to +STDERR+ and everything else goes to +STDOUT+. All of this is, of course, configurable
== Integration Tests
Methadone provides some basic features for executing your CLI and asserting things about it. Methadone::Test::IntegrationTestAssertions documents these.
== Contributing
FAQs
Unknown package
We found that methadone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.