-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
316 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'vscripts' | ||
VScripts.run(ARGV) | ||
VScripts.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
require 'vscripts/commands' | ||
require 'vscripts/command_line' | ||
require 'vscripts/config' | ||
|
||
# Main VScripts module | ||
module VScripts | ||
# Reads the command line arguments | ||
def self.cli | ||
@cli ||= CommandLine.new # Parses command line | ||
end | ||
|
||
# Reads the configuration files | ||
def self.config | ||
@config ||= VScripts::Config.new(cli.global.config) # Parses configuration | ||
end | ||
|
||
# Reads the arguments and runs the given command | ||
def self.run(argv) | ||
cli = CommandLine.new(argv) | ||
command = VScripts::Commands.const_get(cli.command).new(cli.arguments) | ||
command.execute | ||
def self.run | ||
VScripts::Commands.const_get(cli.command).new(cli.arguments).execute | ||
end | ||
end # module VScripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'yaml' | ||
|
||
module VScripts | ||
# VScripts Configuration | ||
class Config | ||
# User's configuration file | ||
DOT_FILE = "#{File.expand_path('~')}/.vscripts.yml" | ||
# Global configuration file | ||
SYSTEM_CONFIG_FILE = '/etc/vscripts/config.yml' | ||
# Global defaults | ||
GLOBAL_DEFAULTS = {} | ||
|
||
# @return [Hash] all configuration options | ||
attr_reader :get | ||
|
||
# Loads class | ||
# @param cfg_file [String] the path to the configuration file | ||
def initialize(cfg_file = nil) | ||
@cfg_file ||= cfg_file | ||
end | ||
|
||
# @return [Hash] the configuration options | ||
def get | ||
@get ||= GLOBAL_DEFAULTS.merge(options) | ||
end | ||
|
||
# Parses the configuration files in order | ||
# @return [Hash] the first configuration hash found | ||
def options | ||
parse(@cfg_file) || | ||
parse(DOT_FILE) || | ||
parse(SYSTEM_CONFIG_FILE) || | ||
{} | ||
end | ||
|
||
# Parses the configuration | ||
# @param file [String] the path to the configuration file | ||
# @return [Hash] the configuration hash | ||
def parse(file) | ||
YAML.load(read(file)) if check_config(file) | ||
end | ||
|
||
# @param (see #parse) | ||
# @return [String] the contents of the file | ||
def read(file) | ||
File.read(file) | ||
end | ||
|
||
# @param (see #parse) | ||
# @return [Boolean] true if the file exists | ||
def check_config(file) | ||
file && File.exist?(file) | ||
end | ||
end # class Config | ||
end # module VScripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.