From d4569810d7e35d0eb75b4397dfbc118251a95b90 Mon Sep 17 00:00:00 2001 From: Postmodern Date: Sun, 7 May 2023 20:26:19 -0700 Subject: [PATCH] Added the `ronin-repos show` command (closes #17). --- README.md | 1 + gemspec.yml | 1 + lib/ronin/repos/cli.rb | 7 ++- lib/ronin/repos/cli/commands/show.rb | 93 ++++++++++++++++++++++++++++ man/ronin-repos-list.1.md | 2 +- man/ronin-repos-show.1.md | 44 +++++++++++++ 6 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 lib/ronin/repos/cli/commands/show.rb create mode 100644 man/ronin-repos-show.1.md diff --git a/README.md b/README.md index bc3258e..b2e8bad 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Commands: new purge remove, rm + show, info update, up ``` diff --git a/gemspec.yml b/gemspec.yml index b92dda7..493f700 100644 --- a/gemspec.yml +++ b/gemspec.yml @@ -23,6 +23,7 @@ generated_files: - man/ronin-repos-list.1 - man/ronin-repos-new.1 - man/ronin-repos-remove.1 + - man/ronin-repos-show.1 - man/ronin-repos-update.1 - man/ronin-repos-purge.1 diff --git a/lib/ronin/repos/cli.rb b/lib/ronin/repos/cli.rb index 84dde65..fea0ff2 100644 --- a/lib/ronin/repos/cli.rb +++ b/lib/ronin/repos/cli.rb @@ -41,9 +41,10 @@ class CLI command_name 'ronin-repos' version Ronin::Repos::VERSION - command_aliases['ls'] = 'list' - command_aliases['up'] = 'update' - command_aliases['rm'] = 'remove' + command_aliases['ls'] = 'list' + command_aliases['up'] = 'update' + command_aliases['rm'] = 'remove' + command_aliases['info'] = 'show' end end diff --git a/lib/ronin/repos/cli/commands/show.rb b/lib/ronin/repos/cli/commands/show.rb new file mode 100644 index 0000000..27a02bb --- /dev/null +++ b/lib/ronin/repos/cli/commands/show.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true +# +# Copyright (c) 2021-2023 Hal Brodigan (postmodern.mod3 at gmail.com) +# +# ronin-repos is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ronin-repos is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with ronin-repos. If not, see . +# + +require 'ronin/repos/cli/command' + +require 'command_kit/printing/fields' +require 'command_kit/printing/lists' + +module Ronin + module Repos + class CLI + module Commands + # + # Prints information about a specific repository in the cache directory. + # + # ## Usage + # + # ronin-repos show [options] REPO + # + # ## Options + # + # -C, --cache-dir DIR Overrides the default cache directory + # -h, --help Print help information + # + # ## Arguments + # + # REPO The repository to display + # + # @since 0.2.0 + # + class Show < Command + + include CommandKit::Printing::Fields + include CommandKit::Printing::Lists + + usage '[options] [REPO]' + + argument :name, required: true, + usage: 'REPO', + desc: 'The repository to display' + + description 'Prints information about a repository in the cache directory' + + man_page 'ronin-repos-show.1' + + # + # Runs the `ronin-repos show` command. + # + # @param [String] name + # The repo name to display. + # + def run(name=nil) + repo = cache_dir[name] + + puts "[ #{repo} ]" + puts + + indent do + print_fields( + 'Name' => repo.name, + 'URI' => repo.url, + 'Files' => nil + ) + + indent do + print_list(repo.list_files) + end + end + rescue RepositoryNotFound => error + print_error(error.message) + exit(-1) + end + + end + end + end + end +end diff --git a/man/ronin-repos-list.1.md b/man/ronin-repos-list.1.md index da419bd..8b4c5a6 100644 --- a/man/ronin-repos-list.1.md +++ b/man/ronin-repos-list.1.md @@ -41,4 +41,4 @@ Postmodern ## SEE ALSO -ronin-repos(1) ronin-repos-install(1) ronin-repos-remove(1) ronin-repos-update(1) ronin-repos-purge(1) +ronin-repos(1) ronin-repos-install(1) ronin-repos-remove(1) ronin-repos-show(1) ronin-repos-update(1) ronin-repos-purge(1) diff --git a/man/ronin-repos-show.1.md b/man/ronin-repos-show.1.md new file mode 100644 index 0000000..deb8d89 --- /dev/null +++ b/man/ronin-repos-show.1.md @@ -0,0 +1,44 @@ +# ronin-repos-show 1 "2023-02-01" Ronin Repos "User Manuals" + +## SYNOPSIS + +`ronin-repos show` [*options*] *NAME* + +## DESCRIPTION + +Prints information about a specific repository in the cache directory. + +## ARGUMENTS + +*NAME* + The repository name to print information about. + +## OPTIONS + +`-C`, `--cache-dir` *DIR* + Overrides the default cache directory. + +`-h`, `--help` + Prints help information. + +## ENVIRONMENT + +*HOME* + Specifies the home directory of the user. Ronin will search for the + `~/.cache/ronin-repos` cache directory within the home directory. + +*XDG_CACHE_HOME* + Specifies the cache directory to use. Defaults to `$HOME/.cache`. + +## FILES + +`~/.cache/ronin-repos` + Installation directory for repositories. + +## AUTHOR + +Postmodern + +## SEE ALSO + +ronin-repos(1) ronin-repos-list(1) ronin-repos-install(1) ronin-repos-remove(1) ronin-repos-update(1) ronin-repos-purge(1)