@@ -47,37 +47,12 @@ public void getOptions(Options options) {
4747 public void run (CliContext context , CommandLine args ) {
4848 this .ctx = context ;
4949 this .io = ctx .getIo ();
50-
51- this .message = args .getOptionValue ("m" );
52- this .noMessage = args .hasOption ("n" );
53- this .openInBrowser = args .hasOption ("o" );
5450 WorkDir workdir = ctx .getWorkDir ();
55- String [] stringArgs = args .getArgs ();
5651
57- if (noMessage && message != null ) {
58- io .errorln ("You can't have the no-message flag and message set at the same time." );
59- printUsage (context );
60- return ;
61- }
62- if (stringArgs .length > 1 ) {
63- io .errorln ("Error: Too many arguments." );
64- printUsage (context );
52+ if (!parseArgs (args )) {
6553 return ;
6654 }
6755
68- if (stringArgs .length == 1 ) {
69- if (!workdir .addPath (stringArgs [0 ])) {
70- io .errorln ("The path '" + stringArgs [0 ] + "' is not valid exercise." );
71- return ;
72- }
73- } else {
74- //TODO replace the following call with workdir.getCurrentExercise()
75- if (!workdir .addPath ()) {
76- io .errorln ("You are not in exercise directory." );
77- return ;
78- }
79- }
80-
8156 if (!ctx .loadBackend ()) {
8257 return ;
8358 }
@@ -104,6 +79,40 @@ public void run(CliContext context, CommandLine args) {
10479 sendPaste (message , exerciseNames .get (0 ));
10580 }
10681
82+ private boolean parseArgs (CommandLine args ) {
83+ WorkDir workdir = ctx .getWorkDir ();
84+ String [] stringArgs = args .getArgs ();
85+
86+ this .message = args .getOptionValue ("m" );
87+ this .noMessage = args .hasOption ("n" );
88+ this .openInBrowser = args .hasOption ("o" );
89+
90+ if (noMessage && message != null ) {
91+ io .errorln ("You can't have the no-message flag and message set at the same time." );
92+ printUsage (ctx );
93+ return false ;
94+ }
95+ if (stringArgs .length > 1 ) {
96+ io .errorln ("Error: Too many arguments." );
97+ printUsage (ctx );
98+ return false ;
99+ }
100+
101+ if (stringArgs .length == 1 ) {
102+ if (!workdir .addPath (stringArgs [0 ])) {
103+ io .errorln ("The path '" + stringArgs [0 ] + "' is not valid exercise." );
104+ return false ;
105+ }
106+ } else {
107+ //TODO replace the following call with workdir.getCurrentExercise()
108+ if (!workdir .addPath ()) {
109+ io .errorln ("You are not in exercise directory." );
110+ return false ;
111+ }
112+ }
113+ return true ;
114+ }
115+
107116 private void sendPaste (String message , String exerciseName ) {
108117 if (message == null ) {
109118 message = "" ;
0 commit comments