File: adding-new-command

package info (click to toggle)
axp 0.2.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,068 kB
  • ctags: 273
  • sloc: perl: 2,727; makefile: 159
file content (49 lines) | stat: -rw-r--r-- 993 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Adding new command to axp is easy, you should create one file (or one
# directory for compositive command). No existing files should be changed.
# To add new-command, you may just copy changelog.pm to new_command.pm
# or use this template.
# To test your new command, run "axp new-command --help", "axp new-command".

package AXP::Command::new_command;
use base 'AXP::Command';

use Arch::Util qw(run_tla);

sub infoline {
	"show the version of tla"
}

sub optusage {
	"[options]"
}

sub options {
	(
		full  => { sh => 'f', desc => "show full output" },
		quiet => { sh => 'q', desc => "show no output" },
	)
}

sub helptext {
	q{
		This is just an example command.

		It shows the output of 'tla --version', partial or full
		depending on the options.
	}
}

sub execute {
	my $self = shift;
	my %opt = %{$self->{options}};

	my @output_lines = run_tla("--version");

	if ($opt{full}) {
		print "$_\n" foreach @output_lines;
	} elsif (!$opt{quiet}) {
		print "$output_lines[0]\n";
	}
}

1;