-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kadai1 rnakamine #26
Kadai1 rnakamine #26
Conversation
fix go modules
Add Struct Commnet
kadai1/imgconv/imgconv.go
Outdated
return err | ||
} | ||
|
||
if err = os.Remove(i.FromPath); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLIツールとして、いきなり元ファイル消してくるのはちょっと怖いかも......
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ebiiim
なるほどです!元ファイルも残す感じにしますね🙆♂️
-delオプションをつけて削除するかユーザー側で判断させるようにしました!
kadai1/cli.go
Outdated
flags.StringVar(&to, "to", "png", "Extensions after conversion") | ||
|
||
if err := flags.Parse(args[1:]); err != nil { | ||
fmt.Fprintln(c.errStream, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fprintlnはファイルへの書き込みを行うので失敗してerrorを返す事があります。
そこのハンドリングをすべきなのと、後にエラーハンドリングの漏れをチェックしようとしたとき(それ用のerrcheckというツールがあります)全て引っかかってしまうので、Runのリターンとしてerrorを返すようにし、Run関数の外部でerrorの処理をする方が良さそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// GetConvertImages retrieves the images to be converted from the specified directory | ||
func GetConvertImages(dir, from, to string) ([]ConvertImage, error) { | ||
var images []ConvertImage | ||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Walkはディレクトリも走査するので、例えばtest.jpgというディレクトリがあった場合に変換対象に含まれてしまいます。あとで画像変換するときに落ちるのですが、この関数内でファイルかどうかはチェックしておいた方が良さそうです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add delete option
Add filetype check
課題1
画像変換コマンドを作ろう
仕様
要件
実行結果
GoDoc