lib/ayadn/app.rb in ayadn-3.0 vs lib/ayadn/app.rb in ayadn-4.0

- old
+ new

@@ -2,31 +2,45 @@ module Ayadn class App < Thor package_name "Ayadn" begin - %w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs set alias errors blacklist mark nicerank debug check diagnostics}.each { |r| require_relative "#{r}" } + %w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs set alias errors blacklist mark nicerank debug check diagnostics stream_object post_object user_object channel_object preferences_object filtered_post_object}.each { |r| require_relative "#{r}" } rescue Interrupt puts "\nExit: stopped by user while launching\n\n" exit end + ## # These methods are intended to be called from the CLI. + # This is managed by the Thor gem. + # + + # "desc" (from Thor) describes what the following method does desc "timeline", "Show your App.net timeline, aka the Unified Stream (-tl)" + # "map" (from Thor) creates an alias for the command + # This one is officially "timeline" but also accepts "unified" map "unified" => :timeline + # "map" (from Thor) is also used to create the command shortcut(s) map "-tl" => :timeline + # "long_desc" (from Thor) is an optional long description for the method (is displayed in the Help) long_desc Descriptions.unified + # "option" (from Thor) creates an available option for the command + # The option name, a symbol, is automatically stringified by Thor + # - "aliases" optionally creates the option shortcut + # - "type" is the type of argument the user can pass to the option: a bool, an array, a number, etc (string by default) option :scroll, aliases: "-s", type: :boolean, desc: "Scroll the stream" option :new, aliases: "-n", type: :boolean, desc: Descriptions.options_new option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already" def timeline + # "options" (the CLI arguments) is a hash automatically generated by Thor Action.new.unified(options) end desc "checkins", "Show the Checkins Stream (-ck)" map "-ck" => :checkins @@ -105,10 +119,12 @@ option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count option :index, aliases: "-i", type: :boolean, desc: Descriptions.options_index option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already" + # The method parameter is the CLI argument + # Here it has a star meaning it will always be an array def mentions(*username) Action.new.mentions(username, options) end desc "userposts @USERNAME", "Show posts by @username (-up)" @@ -153,10 +169,11 @@ option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw option :force, aliases: "-f", type: :boolean, desc: "Force retrieve the actual post id (ignores index)" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already" option :cache, type: :boolean, desc: "Cache the results" option :again, type: :boolean, desc: "Run the last request from cache" + # The argument has no star, it will be a string (by default) def whoreposted(post_id) Action.new.whoreposted(post_id, options) end desc "whostarred POST", "List users who starred a post (-wos)" @@ -466,11 +483,10 @@ map "-P" => :post long_desc Descriptions.post option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post" option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post" option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post" - option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def post(*args) Action.new.post(args, options) end @@ -479,22 +495,20 @@ map "-W" => :write long_desc Descriptions.write option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post" option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post" option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post" - option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def write Action.new.write(options) end desc "pm @USERNAME", "Send a private message to @username" long_desc Descriptions.pmess option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new message" option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new message" option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new message" - option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new message" option :silent, aliases: "-z", type: :boolean, desc: "Do not mark the channel as read" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def pm(*username) Action.new.pmess(username, options) end @@ -503,11 +517,10 @@ map "-C" => :send_to_channel long_desc Descriptions.send_to_channel option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new message" option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new message" option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new message" - option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new message" option :silent, aliases: "-z", type: :boolean, desc: "Do not mark the channel as read" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def send_to_channel(channel_id) Action.new.send_to_channel(channel_id, options) end @@ -516,11 +529,10 @@ map "-R" => :reply long_desc Descriptions.reply option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post" option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post" option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post" - option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post" option :noredirect, aliases: "-n", type: :boolean, desc: "Do not respond to the original post but to the reposted one if possible" option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def reply(id) ayadn = Action.new @@ -533,10 +545,11 @@ Action.new.auto(options) end desc "set TYPE PARAM VALUE", "Set/configure a parameter and save it" long_desc Descriptions.set + # "subcommand" (from Thor) aliases the command to another command in the defined Thor class (here the CLI command "set" is aliased to the "set" command in the "Set" Thor class) subcommand "set", Set desc "alias COMMAND (PARAM)", "Create/delete/list aliases for channels (-A)" map "-A" => :alias long_desc Descriptions.alias @@ -570,32 +583,9 @@ option :text, aliases: "-t", type: :array, desc: "Add custom text" option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" def nowplaying require_relative("nowplaying") Action.new.nowplaying(options) - end - - desc "movie TITLE", "Create a post from a movie title (-NW)" - map "nowwatching" => :movie - map "imdb" => :movie - map "-NW" => :movie - long_desc Descriptions.nowwatching - option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match" - option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" - def movie(*title) - require_relative("nowwatching") - Action.new.nowwatching(title, options) - end - - desc "tvshow TITLE", "Create a post from a TV show title (-TV)" - map "-TV" => :tvshow - long_desc Descriptions.tvshow - option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match" - option :banner, aliases: "-b", type: :boolean, desc: "Inserts the show banner instead of the show poster" - option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)" - def tvshow(*title) - require_relative("tvshow") - Action.new.tvshow(title, options) end desc "random", "Show random posts from App.net (-rnd)" map "-rnd" => :random option :wait, aliases: "-w", type: :numeric, desc: "In seconds, time to wait before next page"