-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
694 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[package] | ||
name = "mpr" | ||
version = "0.1.1" | ||
authors = ["Hunter Wittenborn <[email protected]"] | ||
description = "The official command-line interface for the makedeb Package Repository" | ||
edition = "2021" | ||
|
||
|
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,123 @@ | ||
_mpr_get_pkglist() { | ||
mapfile -t opts < <("${words[0]}" pkglist) | ||
} | ||
|
||
_mpr_gen_compreply() { | ||
mapfile -t COMPREPLY < <(compgen -W "${1}" -- "${2}") | ||
} | ||
|
||
_mpr_pkg_specified_check() { | ||
if [[ "${#nonopts[@]}" -gt 3 ]]; then | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
else | ||
_mpr_get_pkglist | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
fi | ||
} | ||
|
||
_mpr() { | ||
local cur prev words cword | ||
_init_completion || return | ||
|
||
local cmds=( | ||
'clone' | ||
'comment' | ||
'help' | ||
'info' | ||
'list-comments' | ||
'search' | ||
'whoami' | ||
) | ||
local opts=( | ||
'--mpr-url' | ||
'--token' | ||
) | ||
|
||
# Get a list of arguments that are nonoptions. | ||
mapfile -t nonopts < <(printf '%s\n' "${words[@]}" | grep -v '^-') | ||
|
||
if [[ "${#words[@]}" == 2 ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W '${cmds[@]}' "${cur}") | ||
return | ||
fi | ||
|
||
case "${nonopts[1]}" in | ||
clone|info|search) | ||
case "${prev}" in | ||
--token|--mpr-url) | ||
return | ||
;; | ||
esac | ||
|
||
case "${cur}" in | ||
-*) | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
return | ||
;; | ||
*) | ||
_mpr_pkg_specified_check | ||
return | ||
;; | ||
esac | ||
;; | ||
comment) | ||
case "${prev}" in | ||
--token|--mpr-url|--msg) | ||
return | ||
;; | ||
esac | ||
|
||
opts+=('--msg') | ||
case "${cur}" in | ||
-*) | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
return | ||
;; | ||
*) | ||
_mpr_pkg_specified_check | ||
return | ||
;; | ||
esac | ||
;; | ||
help) | ||
return | ||
;; | ||
list-comments) | ||
case "${prev}" in | ||
--token|--mpr-url) | ||
return | ||
;; | ||
--paging) | ||
opts=('auto' 'never' 'always') | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
return | ||
;; | ||
esac | ||
|
||
opts+=('--paging') | ||
case "${cur}" in | ||
-*) | ||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
return | ||
;; | ||
*) | ||
_mpr_pkg_specified_check | ||
return | ||
;; | ||
esac | ||
;; | ||
whoami) | ||
case "${prev}" in | ||
--token|--mpr-url) | ||
return | ||
;; | ||
esac | ||
|
||
_mpr_gen_compreply '${opts[@]}' "${cur}" | ||
return | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _mpr mpr | ||
# vim: set sw=4 expandtab: |
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,59 @@ | ||
= MAKEDEB(1) | ||
:doctype: manpage | ||
:hardbreaks: | ||
:manmanual: MPR CLI | ||
:mansource: MAKEDEB $${MPR_VERSION} | ||
|
||
== NAME | ||
mpr - The official command-line interface for the makedeb Package Repository | ||
|
||
== SYNOPSIS | ||
*mpr* clone _pkgbase_ [_options_] ... | ||
*mpr* comment _pkgbase_ [_options_] ... | ||
*mpr* info _pkgname_ [_options_] ... | ||
*mpr* list-comments _pkgbase_ [_options_] ... | ||
*mpr* search _query_ ... [_options_] ... | ||
*mpr* whoami [_options_] ... | ||
|
||
== DESCRIPTION | ||
*mpr* is a command-line interface for interacting with the makedeb Package Repository. | ||
|
||
The *comment* and *whoami* commands both require authentication via an API key in order to run. An API key can be obtained via the MPR web interface on the user's account page, and can be passed into this program via the *--token* argument or the *MPR_TOKEN* environment variable, the former being described in *OPTIONS*, and the latter in *ENVIRONMENT*. | ||
|
||
*clone*:: | ||
Clone the build files for a package base from the MPR. | ||
|
||
*comment*:: | ||
Comment on a package base's page on the MPR. | ||
|
||
*info*:: | ||
Get information about a package on the MPR. | ||
|
||
*list-comments*:: | ||
List comments of a package base on the MPR. | ||
|
||
*search*:: | ||
Search the package list on the MPR. | ||
|
||
*whoami*:: | ||
Show the currently authenticated user. | ||
|
||
== OPTIONS | ||
Run each command with *--help* to see available options. | ||
|
||
== BUGS | ||
Issues, as well as feature requests, should be reported on the project's GitHub page: | ||
|
||
https://github.com/makedeb/mpr-cli/issues | ||
|
||
Matrix is also used as our primary method of real-time communication, being where most discussions (outside of the issue tracker) take place. All rooms are joined via a Matrix space, which can be accessed via the following: | ||
|
||
#makedeb:hunterwittenborn.com | ||
|
||
== AUTHORS | ||
Hunter Wittenborn <\[email protected]> | ||
|
||
A full list of contributors can be found by running *git shortlog -esn* in the MPR CLI's Git repository (linked under *BUGS*). | ||
|
||
== SEE ALSO | ||
*makedeb*(8) |
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,112 @@ | ||
use clap::{self, Arg, Command, PossibleValue}; | ||
|
||
#[rustfmt::skip] | ||
pub fn get_cmd() -> Command<'static> { | ||
Command::new(clap::crate_name!()) | ||
.version(clap::crate_version!()) | ||
.about(clap::crate_description!()) | ||
.arg_required_else_help(true) | ||
.arg( | ||
Arg::new("token") | ||
.help("The API token to authenticate to the MPR with") | ||
.long("token") | ||
.env("MPR_TOKEN") | ||
.hide_env_values(true) | ||
.global(true) | ||
.takes_value(true) | ||
) | ||
.arg( | ||
Arg::new("mpr-url") | ||
.help("URL to access the MPR from") | ||
.long("mpr-url") | ||
.env("MPR_URL") | ||
.hide_env_values(true) | ||
.global(true) | ||
.takes_value(true) | ||
.default_value("https://mpr.makedeb.org") | ||
) | ||
.subcommand( | ||
Command::new("clone") | ||
.about("Clone a package base from the MPR") | ||
.arg( | ||
Arg::new("pkg") | ||
.help("The package to clone") | ||
.required(true) | ||
) | ||
) | ||
.subcommand( | ||
Command::new("comment") | ||
.arg_required_else_help(true) | ||
.about("Comment on a package page") | ||
.arg( | ||
Arg::new("pkg") | ||
.help("The package to comment on") | ||
.required(true) | ||
.takes_value(true) | ||
) | ||
.arg( | ||
Arg::new("msg") | ||
.help("The comment to post") | ||
.short('m') | ||
.long("msg") | ||
) | ||
) | ||
.subcommand( | ||
Command::new("info") | ||
.arg_required_else_help(true) | ||
.about("View information about a package") | ||
.arg( | ||
Arg::new("pkg") | ||
.help("The package to view") | ||
.required(true) | ||
) | ||
.arg( | ||
Arg::new("web") | ||
.help("Open the page for the package in a web browser") | ||
.short('w') | ||
.long("web") | ||
) | ||
) | ||
.subcommand( | ||
Command::new("list-comments") | ||
.arg_required_else_help(true) | ||
.about("List the comments on a package") | ||
.arg( | ||
Arg::new("pkg") | ||
.help("The package to view comments for") | ||
.required(true) | ||
) | ||
.arg( | ||
Arg::new("paging") | ||
.help("When to send output to a pager") | ||
.long("paging") | ||
.takes_value(true) | ||
.default_value("auto") | ||
.value_parser([ | ||
PossibleValue::new("auto"), | ||
PossibleValue::new("always"), | ||
PossibleValue::new("never") | ||
]) | ||
) | ||
) | ||
// Used in autocompletions. | ||
.subcommand( | ||
Command::new("pkglist") | ||
.hide(true) | ||
) | ||
.subcommand( | ||
Command::new("search") | ||
.about("Search the MPR for a package") | ||
.arg_required_else_help(true) | ||
.arg( | ||
Arg::new("pkg") | ||
.required(true) | ||
.help("The query to search for") | ||
.multiple_values(true) | ||
) | ||
) | ||
.subcommand( | ||
Command::new("whoami") | ||
.about("Show the currently authenticated user") | ||
) | ||
} |
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.