@@ -20,6 +20,10 @@ public static String run(String... args) {
2020 }
2121
2222 String commandName = args [0 ];
23+ if (Objects .equals (commandName , "-h" ) || Objects .equals (commandName , "--help" )){
24+ printHelpMessage ();
25+ return result ;
26+ }
2327
2428 CommandLine cmd = getCmd (Arrays .copyOfRange (args , 1 , args .length ));
2529 String model = cmd .getOptionValue ("model" );
@@ -40,6 +44,7 @@ public static String run(String... args) {
4044
4145 } catch (Exception e ) {
4246 e .printStackTrace ();
47+ System .out .println ("Run './casbin --help or ./casbin -h' for usage." );
4348 System .exit (1 );
4449 }
4550 return result ;
@@ -77,4 +82,36 @@ private static CommandLine getCmd(String[] args) throws ParseException {
7782 CommandLineParser parser = new DefaultParser ();
7883 return parser .parse (options , args );
7984 }
85+
86+ private static void printHelpMessage () {
87+ System .out .println (" Usage: ./casbin [Method] [options] [args]\n " +
88+ "\n " +
89+ " Casbin is a powerful and efficient open-source access control library.\n " +
90+ " It provides support for enforcing authorization based on various access control models.\n " +
91+ "\n " +
92+ " Method:\n " +
93+ " enforce Test if a 'subject' can access an 'object' with a given 'action' based on the policy\n " +
94+ " enforceEx Check permissions and get which policy it matches\n " +
95+ " addFunction Add custom function\n " +
96+ " addPolicy Add a policy rule to the policy file\n " +
97+ " removePolicy Remove a policy rule from the policy file\n " +
98+ " For more method, visit https://github.com/casbin/jcasbin\n " +
99+ "\n " +
100+ " Options:\n " +
101+ " -m, --model <model> The path of the model file or model text. Please wrap it with \" \" and separate each line with \" |\" \n " +
102+ " -p, --policy <policy> The path of the policy file or policy text. Please wrap it with \" \" and separate each line with \" |\" \n " +
103+ " -AF, --addFunction <functionDefinition> Add custom function. Please wrap it with \" \" and separate each line with \" |\" \n " +
104+ "\n " +
105+ " args:\n " +
106+ " Parameters required for the method\n " +
107+ "\n " +
108+ " Examples:\n " +
109+ " ./casbin enforce -m \" examples/rbac_model.conf\" -p \" examples/rbac_policy.csv\" \" alice\" \" data1\" \" read\" \n " +
110+ " ./casbin enforceEx -m \" examples/rbac_model.conf\" -p \" examples/rbac_policy.csv\" \" alice\" \" data1\" \" read\" \n " +
111+ " ./casbin addPolicy -m \" examples/rbac_model.conf\" -p \" examples/rbac_policy.csv\" \" alice\" \" data2\" \" write\" \n " +
112+ " ./casbin enforce -m \" your_model.conf\" -p \" examples/keymatch_policy.csv\" -AF \" yourFunctionDefinition\" \" alice\" \" /alice_data/resource1\" \" GET\" \n " +
113+ "\n " +
114+ " For more information, visit https://github.com/casbin/casbin" );
115+
116+ }
80117}
0 commit comments