Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rustで作った自作コマンド群の話
Search
garebare
June 17, 2022
Programming
180
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rustで作った自作コマンド群の話
6月17日に行われたNEW DEBUG!!!!で発表した資料です。
https://caspur.wintu.dev/front/lives/264
garebare
June 17, 2022
More Decks by garebare
See All by garebare
ペンギンをおすすめする
garebareda
0
61
hey-techcamp-2022
garebareda
2
80
クリーンアーキテクチャ をGoでする場合に不要な Interfaceは消しやがれ
garebareda
0
160
自作Git作った話
garebareda
3
810
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
880
Vtuberをやりたくなりました
garebareda
1
93
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
300
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
150
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
240
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
140
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
360
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
240
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
130
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
180
FreeBSDでZabbixを動かす
kenkino
0
300
wkhtmltopdfの次どうするか問題2026
willnet
2
1.3k
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
290
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
So, you think you're a good person
axbom
PRO
2
2.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
380
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
The browser strikes back
jonoalderson
0
1.7k
Raft: Consensus for Rubyists
vanstee
142
7.7k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
340
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Navigating Weather and Climate Data
rabernat
0
520
Transcript
Rustで作った 自作コマンド群の話 @garebare521
自己紹介 名前:ガレバレ とうとうインターンシップ始めた 授業とインターンシップで死にそうに なってる コーヒーの器具を一式買った
このスライドは前座
皆さん、自作コマンド 作りたくないですか?
作りたいですよね?
残念ですがそんなことを思っている間に 私が先に作りました
でもフルスクラッチではないので 皆さん頑張って下さい
最初に下準備
とりあえず、全部に実装するトレイトを定義する pub trait Commands { fn help(&self); fn version(&self); fn
name(&self) -> &str; fn run(&self) -> Result<(), String>; }
helpとversionのオプションはデフォルトで実装 pub trait Commands { fn print_help(&self, options: &Vec<String>, arg:
&str) -> bool { if options.contains(&"--help".to_string()) || options.contains(&"-help".to_string()) || options.contains(&"-h".to_string()) || arg == "help" { self.help(); return true; } false } }
parser 毎度同じみのパーサー 一番最初に来たものはコマンド名として処理する ハイフンがついているものはオプションとして処理する 何もついてないのは引数として処理する
オプション let options = args.iter().filter(|arg| arg.starts_with(“-”)) .map(|arg| arg.to_string()) .collect(); Rustの場合こんな感じにすれば最初の文字がハイフンで始
まってる文字列が取れる
引数 let args = args.iter().filter(|arg| !arg.starts_with(“-”)) .map(|arg| arg.to_string()) .collect(); 条件を反転させるだけ
- cat - ls - ps - rm - touch
- witch 作ったコマンド
ざっくり紹介します
cat 単純にRustでファイルを開いて一行ずつ読み込んで表示して る -e 最後に$を入れる -n 行番号をつける -b 空白行を入れずに行番号をつける
エンジニアの皆様なら 実装は想像つきますよね????
ls std::os::unix::fs::{MetadetaExt, PremisstionsExt}でメタデー タと権限を取得 あとはディレクトリを回して表示してる 存在している権限はライブラリで取得 -a 隠しファイルも表示 -l ディテールの表示
-R 再帰的に表示 -r 逆順で表示
ps ライブラリを使ってuidとプロセスを取得 大体ライブラリの例通り実装してオプションにより表示を制限す ればいい -x 端末操作以外の全てのプロセスも表示 -a 他ユーザーのも含めてすべてのプロセスを表示 -l ディテールも表示
rm Rustでディレクトリを回して単純に削除してる -r 再帰的にファイルを削除 -i 削除する際に同意を求める
touch 実はファイルを生成するコマンドじゃない! ライブラリを使って編集時間を取得して更新もしている metadetaから編集時間などを取得するためまぁまぁ実装する のに疲れた -a 最終アクセスした時間をアップデート -m 最終編集した時間をアップデート -r
指定したファイルのタイムスタンプと同じ日時にする
touch とは言えファイルの生成もできるようにした
witch 環境変数PATHを全部読み込んで分割して表示してる -a フルパスの表示
これで全部!