mtool - Command-Line Tool

Alat baris perintah serbaguna untuk pemrosesan teks, dengan subperintah, konfigurasi runtime, logging, dan unit test.

Struktur Kode #

FileTanggung Jawab
cli.h/.cParsing argumen + subperintah
config.h/.cLoader file konfigurasi .mtoolrc
file_processor.h/.cOperasi file: head, tail, stats, grep
logger.h/.cLogger dengan level DEBUG/INFO/WARN/ERROR
main.cEntry point + dispatch subperintah
tests.cUnit test

Build #

bash
make           # Bangun tool utama
make test      # Jalankan unit test
./mtool help   # Tampilkan usage

Subperintah #

SubperintahFungsi
count FILEHitung jumlah baris di FILE
head -n N FILECetak N baris pertama (default 10)
tail -n N FILECetak N baris terakhir
stats FILECetak jumlah baris, kata, karakter
grep PATTERN [-i] FILECetak baris yang mengandung PATTERN
helpTampilkan pesan bantuan
versionTampilkan versi

File Konfigurasi .mtoolrc #

Bila file .mtoolrc ada di direktori kerja saat ini, tool memuat opsi:

ini
# Konfigurasi mtool
log_level = DEBUG       # DEBUG | INFO | WARN | ERROR
default_count = 25      # default untuk head/tail

Contoh Sesi #

bash
$ echo -e "alpha\nbeta\ngamma\ndelta" > /tmp/sample.txt
$ ./mtool head -n 2 /tmp/sample.txt
alpha
beta
$ ./mtool stats /tmp/sample.txt
       4 baris        4 kata       23 karakter  /tmp/sample.txt
$ ./mtool grep -i GAMMA /tmp/sample.txt
gamma