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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
62
hey-techcamp-2022
garebareda
2
81
クリーンアーキテクチャ をGoでする場合に不要な Interfaceは消しやがれ
garebareda
0
160
自作Git作った話
garebareda
3
870
Rustで自作言語のインタプリタ作って Webで動くようにした話
garebareda
0
880
Vtuberをやりたくなりました
garebareda
1
94
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
530
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.1k
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
Simple Storage Service(S3) is not simple
iwatsukayura
0
250
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
パーソナライズPodcastを作った話
repunit11
0
130
ジョジョの世界をXRで再現する
mofurune
0
150
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
690
Java 27新機能 / Java 27 new features
kishida
2
210
Unity6 URPによる海底をテーマにしたVJシステムの解説 | Unity Shader 完全に理解した 勉強会
gam0022
0
350
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
YesSQL, Process and Tooling at Scale
rocio
174
15k
4 Signs Your Business is Dying
shpigford
187
23k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
520
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
470
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
870
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
860
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
270
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
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 フルパスの表示
これで全部!