From 034acd4bd436e7a22d7b26bac8d58b9fbd1f47b5 Mon Sep 17 00:00:00 2001 From: Thomas Leitner Date: Wed, 5 Apr 2006 14:12:46 +0000 Subject: [PATCH] * small changes --- doc/src/tutorial.page | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/src/tutorial.page b/doc/src/tutorial.page index ca23059..e6df948 100644 --- a/doc/src/tutorial.page +++ b/doc/src/tutorial.page @@ -3,7 +3,50 @@ title: Tutorial inMenu: true orderInfo: 6 --- -h2. Tutorial +h2. Quickstart + +Here are some short code fragments which show how to use cmdparse. A complete example app can be +found later in the "tutorial section":#tutorial. + +Defining commands using classes: +
+class TestCmd < CmdParse::Command
+  def initialize
+    super('test', true)
+    self.add_command(TestSubCmd.new)
+  end
+end
+
+class TestSubCmd < CmdParse::Command
+  def initialize
+    super('sub',false)
+  end
+
+  def execute (args)
+    puts "Hallo #{args}"
+  end
+end
+
+cmd = CmdParse::CommandParser.new( true )
+cmd.add_command(TestCmd.new)
+
+ +Defining command using the basic @CmdParse::Command@ class: +
+cmd = CmdParse::CommandParser.new( true )
+testcmd = CmdParse::Command.new( 'test', true )
+testcmd.short_desc = "Short desc"
+cmd.add_command( testcmd )
+
+sub = CmdParse::Command.new( 'sub', false )
+sub.short_desc = "Add an IP address"
+sub.set_execution_block do |args|
+  puts "Hallo #{args}"
+end
+testcmd.add_command( sub )
+
+ +h2(#tutorial). Tutorial The complete code for this example can be found in the file @net.rb@ of the @cmdparse@ package!