-# Username is syntactically invalid.
-class InvalidUserError < StandardError
-end
+# An error indicating that a username is syntactically invalid.
+class InvalidUserError < StandardError; end
-# Domain is syntactically invalid.
-class InvalidDomainError < StandardError
-end
+# An error indicating that a domain is syntactically invalid.
+class InvalidDomainError < StandardError; end
+# An error indicating that a user does not exist.
+class NonexistentUserError < StandardError; end
-# Used to indicate that an user does not exist.
-class NonexistentUserError < StandardError
-end
+# An error indicating that a domain does not exist.
+class NonexistentDomainError < StandardError; end
-# Used to indicate that a domain does not exist.
-class NonexistentDomainError < StandardError
-end
-
-
-# When you try to rename a user on top of one that already exists.
-class UserAlreadyExistsError < StandardError
-end
+# An error indicating that some user already exists. For example, if
+# one tries to rename a user and the destination user already exists.
+class UserAlreadyExistsError < StandardError; end
module ExitCodes
+ # Everything went better than expected.
SUCCESS = 0
- FILESYSTEM_ERROR = 1
- DATABASE_ERROR = 2
- BAD_COMMAND_LINE = 3
+
+ # The command-line arguments were not what we expected.
+ BAD_COMMAND_LINE = 1
end
class Filesystem
+ # Convenience methods for working with the filesystem. This class
+ # only provides static methods, to be used analogously to the File
+ # class (for example, File.directory?).
- def self.begins_with_dot(path)
+
+ # Return whether or not the given path begins with a dot (ASCII
+ # period).
+ #
+ # @param path [String] the path whose first character you want to check.
+ #
+ # @return [Boolean] whether or not *path* begins with an ASCII period.
+ #
+ def self.begins_with_dot?(path)
return (path[0..0] == '.')
end
+
+ # Get a list of all real subdirectories of the given directory.
+ #
+ # @param dir [String] the directory whose subdirectories you want.
+ #
+ # @return [Array<String>] a list of subdirectories of *dir*, not
+ # including the pseudo-directories "." and ".." (the current/parent
+ # directories).
+ #
def self.get_subdirs(dir)
subdirs = []
Dir.open(dir) do |d|
d.each do |entry|
relative_path = File.join(dir, entry)
- if (File.directory?(relative_path) and not begins_with_dot(entry))
+ if File.directory?(relative_path) and not self.begins_with_dot?(entry)
subdirs << entry
end
end
-# Load the rest of the code we'll use. This loads only what we'll need
-# in the executable. The library files are supposed to require what
-# they need.
+# Load only the files needed by our executable. The library files are
+# supposed to require what they need themselves.
require 'common/configuration'
require 'common/errors'