-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refatorando as opções de command line #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,7 @@ target | |
.project | ||
.settings | ||
.build/ | ||
.idea/ | ||
cotuba-cli.iml | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package cotuba.cli; | ||
|
||
import org.apache.commons.cli.*; | ||
|
||
public class OptionCLIReader { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O projeto já estava usando as variáveis em português. Por isso, acho que seria melhor manter o nome da classe em português. |
||
|
||
private String nomeDoDiretorioDosMD; | ||
private String nomeDoFormatoDoEbook; | ||
private String nomeDoArquivoDeSaidaDoEbook; | ||
private boolean modoVerboso = false; | ||
|
||
public OptionCLIReader(String [] args) { | ||
Options options = new Options(); | ||
|
||
options.addOption(new Option("d", "dir", true, "Diretório que contem os arquivos md. Default: diretório atual.")); | ||
options.addOption(new Option("f", "format", true, "Formato de saída do ebook. Pode ser: pdf ou epub. Default: pdf")); | ||
options.addOption(new Option("o", "output", true, "Arquivo de saída do ebook. Default: book.{formato}.")); | ||
options.addOption(new Option("v", "verbose", false, "Habilita modo verboso.")); | ||
|
||
CommandLineParser cmdParser = new DefaultParser(); | ||
HelpFormatter ajuda = new HelpFormatter(); | ||
CommandLine cmd; | ||
|
||
try { | ||
cmd = cmdParser.parse(options, args); | ||
} catch (ParseException e) { | ||
System.err.println(e.getMessage()); | ||
ajuda.printHelp("cotuba", options); | ||
System.exit(1); | ||
return; | ||
} | ||
|
||
this.nomeDoDiretorioDosMD = cmd.getOptionValue("dir"); | ||
this.nomeDoFormatoDoEbook = cmd.getOptionValue("format"); | ||
this.nomeDoArquivoDeSaidaDoEbook = cmd.getOptionValue("output"); | ||
this.modoVerboso = cmd.hasOption("verbose"); | ||
Comment on lines
+13
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Você acha que seria bom reorganizar esse trecho de código? Se sim, como você faria? |
||
} | ||
|
||
public String getNomeDoDiretorioDosMD() { | ||
return nomeDoDiretorioDosMD; | ||
} | ||
|
||
public String getNomeDoFormatoDoEbook() { | ||
return nomeDoFormatoDoEbook; | ||
} | ||
|
||
public String getNomeDoArquivoDeSaidaDoEbook() { | ||
return nomeDoArquivoDeSaidaDoEbook; | ||
} | ||
|
||
public boolean isModoVerboso() { | ||
return modoVerboso; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boa!