Skip to content

Commit

Permalink
Improve documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 14, 2024
1 parent 138a8e1 commit 62a1d8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/command/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ pub fn add_admin(args: &AddAdminArgs) -> Result<()> {
}

#[derive(Args)]
pub struct AddAllowedActionArgs {
pub struct AddAdminActionArgs {
pub admin_name: String,
pub action: String,
}

pub fn add_allowed_action(args: &AddAllowedActionArgs) -> Result<()> {
pub fn add_admin_action(args: &AddAdminActionArgs) -> Result<()> {
rpc::call(
"add_allowed_action",
json!({"admin_name": args.admin_name, "action": args.action}),
"add_admin_action",
json!({"admin": args.admin_name, "action": args.action}),
)?
.print()
}

#[derive(Args)]
pub struct RemoveAllowedActionArgs {
pub struct RemoveAdminActionArgs {
pub admin_name: String,
pub action: String,
}

pub fn remove_allowed_action(args: &RemoveAllowedActionArgs) -> Result<()> {
pub fn remove_admin_action(args: &RemoveAdminActionArgs) -> Result<()> {
rpc::call(
"remove_allowed_action",
json!({"admin_name": args.admin_name, "action": args.action}),
"remove_admin_action",
json!({"admin": args.admin_name, "action": args.action}),
)?
.print()
}
6 changes: 3 additions & 3 deletions src/command/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub fn boost_element(args: &BoostElementArgs) -> Result<()> {
}

#[derive(Args)]
pub struct GetBoostsArgs {}
pub struct GetBoostedElementsArgs {}

pub fn get_boosts(_: &GetBoostsArgs) -> Result<()> {
rpc::call("get_boosts", json!({}))?.print()
pub fn get_boosted_elements(_: &GetBoostedElementsArgs) -> Result<()> {
rpc::call("get_boosted_elements", json!({}))?.print()
}

#[derive(Args)]
Expand Down
46 changes: 33 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,59 @@ struct Cli {

#[derive(Subcommand)]
enum Commands {
// Setup
/// Set a JSON RPC API URL
SetServer(command::setup::SetServerArgs),
/// Try to login and save password for future calls, if successful
Login(command::setup::LoginArgs),
/// Show all locally cached data
State(command::setup::StateArgs),
// Admin
/// Create a new admin user. New admins have no permissions by default, use add-admin-action to allow certain acitons
AddAdmin(command::admin::AddAdminArgs),
AddAllowedAction(command::admin::AddAllowedActionArgs),
RemoveAllowedAction(command::admin::RemoveAllowedActionArgs),
// Common
/// Allow other admin to perform a certain action. You must be super admin to use this command
AddAdminAction(command::admin::AddAdminActionArgs),
/// Block other admin from using a certain action. You must be super admin to use this command
RemoveAdminAction(command::admin::RemoveAdminActionArgs),
/// Return all entities matching provided search query. Currently, only areas are returned
Search(command::common::SearchArgs),
// Element
/// Fetch element by a numeric or OSM (node:12345) id. You can also use node=12345 format
GetElement(command::element::GetElementArgs),
/// Set tag to a certain element. You can use either numeric or OSM (node:12345) id. Every tag must be a valid JSON value. Nulls are not allowed and will be interpreted as deletion requests
SetElementTag(command::element::SetElementTagArgs),
/// Remove tag from a certain element. You can use either numeric or OSM (node:12345) id
RemoveElementTag(command::element::RemoveElementTagArgs),
/// Add coment to a certain element. You can use either numeric or OSM (node:12345) id
AddElementComment(command::element::AddElementCommentArgs),
/// Boost an element for a set number of days. You can use either numeric or OSM (node:12345) id
BoostElement(command::element::BoostElementArgs),
GetBoosts(command::element::GetBoostsArgs),
/// Get all boosted elements
GetBoostedElements(command::element::GetBoostedElementsArgs),
/// Fetch the latest Overpass snapshot and merge it with cached elements. It may take a long time and it's not supposed to be called manually
SyncElements(command::element::SyncElementsArgs),
/// Generate icon:android tags for a specific element id range
GenerateElementIcons(GenerateElementIconsArgs),
/// Generate category tags for a specific element id range
GenerateElementCategories(GenerateElementCategoriesArgs),
/// Generate issues tags for a specific element id range. This command is supposed to be called automatically by a BTC Map server internal shceduler
GenerateElementIssues(GenerateElementIssuesArgs),
// Area
/// Fetch area by either numeric id or string alias (th)
GetArea(command::area::GetAreaArgs),
/// Set tag to a certain area. You can use either numeric id or a string alias (th)
SetAreaTag(command::area::SetAreaTagArgs),
/// Remove tag from a certain area. You can use either numeric id or a string alias (th)
RemoveAreaTag(command::area::RemoveAreaTagArgs),
/// Set icon to a certain area. You can use either numeric id or a string alias (th). Icon needs to be base64-encoded, and you also need to provide file extension
SetAreaIcon(command::area::SetAreaIconArgs),
/// Ensure that elements and areas are correctly mapped to each other. You need to provide element id range in order to operate on a specific slice of elements
GenerateAreasElementsMapping(command::area::GenerateAreasElementsMappingArgs),
// User
/// Fetch the latest user actions. You need to provide OSM username and the number of latest entries you are interested in
GetUserActivity(command::user::GetUserActivityArgs),
// Report
/// Generate daily reports. It will skip report generation if current date is already covered
GenerateReports(command::report::GenerateReportsArgs),
/// Find which countries were trending during a certain time period. Arguments should be valid ISO dates (example: 2024-09-10)
GetTrendingCountries(command::report::GetTrendingCountriesArgs),
/// Find which communities were trending during a certain time period. Arguments should be valid ISO dates (example: 2024-09-10)
GetTrendingCommunities(command::report::GetTrendingCommunitiesArgs),
/// Find which countries had the most comments during a certain time period. Arguemnts should be valid ISO dates (example: 2024-09-10)
GetMostCommentedCountries(command::report::GetMostCommentedCountriesArgs),
}

Expand Down Expand Up @@ -92,8 +112,8 @@ fn main() -> Result<()> {
Commands::State(_) => Err("supposed to be unreachable".into()),
// Admin
Commands::AddAdmin(args) => command::admin::add_admin(args),
Commands::AddAllowedAction(args) => command::admin::add_allowed_action(args),
Commands::RemoveAllowedAction(args) => command::admin::remove_allowed_action(args),
Commands::AddAdminAction(args) => command::admin::add_admin_action(args),
Commands::RemoveAdminAction(args) => command::admin::remove_admin_action(args),
// Common
Commands::Search(args) => command::common::search(args),
// Element
Expand All @@ -102,7 +122,7 @@ fn main() -> Result<()> {
Commands::RemoveElementTag(args) => element::remove_element_tag(args),
Commands::AddElementComment(args) => element::add_element_comment(args),
Commands::BoostElement(args) => element::boost_element(args),
Commands::GetBoosts(args) => element::get_boosts(args),
Commands::GetBoostedElements(args) => element::get_boosted_elements(args),
Commands::SyncElements(args) => element::sync_elements(args),
Commands::GenerateElementIcons(args) => element::generate_element_icons(args),
Commands::GenerateElementCategories(args) => element::generate_element_categories(args),
Expand Down

0 comments on commit 62a1d8b

Please sign in to comment.