ryukinix / mal

MAL: A MyAnimeList Command Line Interface [BROKEN: BLAME MyAnimeList]
https://mal.readthedocs.io
Other
109 stars 9 forks source link

Refactor command line interface using a symmetric and better abstraction #10

Closed ryukinix closed 7 years ago

ryukinix commented 7 years ago

For now I don't use any lib for parsing command line arguments and without abstraction in the major cases we don't have power.

We need a good way and easy to use and develop more arguments for mal.

config
------
$ mal config
:: streaming:
1. superanimes (free server) (no credentials need) (pt-br)
2. crunchbag (paid server) (need credentials) (multilanguage)
select streaming source: 1
:: player
1. vlc
2. mplayer
select your player: 1
:: download:
1. anbient (pt-br)
2. another (?)
select download source: 1

download
--------
$ mal lain download next
==> downloading the epi ~x~

watch
--------
$ mal lain watch next
~opening your default player

This need work well as the default features for now.

alexkubica commented 7 years ago

Would you like to use something like getopt?

ryukinix commented 7 years ago

I was thinking to use a more abstract library like argparse

alexkubica commented 7 years ago

Looks kinda the same to me :) So for this issue you just wan't to use a library to parse arguments, right? No extra features that I'm missing here?

ryukinix commented 7 years ago

Is just that! A good way to parse and we can add more features later without big problems.

alexkubica commented 7 years ago

I see, I think I can do that!

ryukinix commented 7 years ago

Thanks! I will be glad for any improve on this.

alexkubica commented 7 years ago

I'm walking through the documentation of argparse and I think the arguments should be changed to make implementation easier. I was thinking about something like:

--inc -i N anime-by-regex
--dec -d N anime-by-regex
--section -s [watching | plan to watch | ... | rewatching]
--list-all -a
--find -f anime-by-regex
--help -h

The first argument received will be parsed and others will be ignored, for example if I would enter:

mal -a -h

This would just list all animes without printing help message. Also, I noticed that mal currently works on anime category only, how about adding an argument to choose the category which will default to anime right now? And in the future we could implement a manga option.

ryukinix commented 7 years ago

Here we have a problem. I don't wants use the GNU standard for main commands, like search, inc, dec, config, login and so on. Tools like https://github.com/beetbox/beets has a more simple usage, like http://platformio.org/ too. (tools written in python!)

Here is the help of beet

❯ beet   
Usage: 
  beet COMMAND [ARGS...]
  beet help COMMAND

Options:
  --format-item=FORMAT_ITEM
                        print with custom format
  --format-album=FORMAT_ALBUM
                        print with custom format
  -l LIBRARY, --library=LIBRARY
                        library database file to use
  -d DIRECTORY, --directory=DIRECTORY
                        destination music directory
  -v, --verbose         log more details (use twice for even more)
  -c CONFIG, --config=CONFIG
                        path to configuration file
  -h, --help            show this help message and exit

Commands:
  config            show or edit the user configuration
  convert           convert to external location
  duplicates (dup)  List duplicate tracks or albums.
  export            export data from beets
  fields            show fields available for queries and format strings
  help (?)          give detailed help on a specific sub-command
  import (imp, im)  import new music
  info              show file metadata
  list (ls)         query the library
  modify (mod)      change metadata fields
  move (mv)         move or copy items
  play              send music to a player as a playlist
  remove (rm)       remove matching items from the library
  stats             show statistics about the library or a query
  update (upd, up)  update the library
  version           output version information
  write             write tag information to files
❯ platformio
Usage: platformio [OPTIONS] COMMAND [ARGS]...

Options:
  --version          Show the version and exit.
  -f, --force        Force to accept any confirmation prompts.
  -c, --caller TEXT  Caller ID (service).
  -h, --help         Show this message and exit.

Commands:
  boards       Pre-configured Embedded Boards
  ci           Continuous Integration
  init         Initialize new PlatformIO based project
  lib          Library Manager
  platforms    Platforms and Packages Manager
  run          Process project environments
  serialports  List or Monitor Serial ports
  settings     Manage PlatformIO settings
  update       Update installed Platforms, Packages and Libraries
  upgrade      Upgrade PlatformIO to the latest version

BTW, I wanna the CLI more minimal as possible. Tools with a lot of arguments is pretty mess. I have a sugestion for this arch:

mal search <anime-regex>
mal inc  <anime-regex>
mal dec <anime-regex>
mal login
mal config
mal section <section-name>
mal download¹ <anime-regex>
mal watch² <anime-regex>

¹ and ² has a decription here #3 #4

We need thinking about the final result more rather the difficult of implementation. If we need use GNU standard for arguments, I prefer continues parsing manually the arguments with the current usage. If argparse makes the implementation of this parsing more hard we have two options: 1. search for another library; 2. create a minimal abstraction for add arguments that way.

About add the category options I'm ok with that, on the start I see some people talking about the lack of support for mangs. But I need to be clear: I really wants avoid GNU standard for arguments.

alexkubica commented 7 years ago

I understand, i'll go by your suggestion. Do you think each command should be a sub-command?

ryukinix commented 7 years ago

I think is pretty like sub-commands. Another idea is using argparse like git parse: http://chase-seibert.github.io/blog/2014/03/21/python-multilevel-argparse.html

ryukinix commented 7 years ago

Thanks for understand it, and again, thanks for the help. Will really cool if we can do that. Another tasks like #3 and #4 will more easily to add too.

alexkubica commented 7 years ago

I've started working on the sub commands on this branch. I'm having a difficult time refactoring the function isomorphic_increment on cli.py. How can it be made simpler that it will get the anime regex and +1 or -1 instead of getting the args?

alexkubica commented 7 years ago

Never mind, it seems we don't need it any more, this works: https://github.com/AlexK-IL/mal/commit/762c8f708859c24433925bd7627214d60a283ae1.

alexkubica commented 7 years ago

Since https://github.com/ryukinix/mal/pull/12 was merged, I'm closing this issue.

ryukinix commented 7 years ago

Good job!