From 687788767f0ddab95c8b50b298f568a638d1a79b Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Wed, 15 Jul 2020 10:47:27 +0000 Subject: [PATCH] Use auto when an unknown sorting method is passed --- src/library.cr | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/library.cr b/src/library.cr index b33f844..2aa96e6 100644 --- a/src/library.cr +++ b/src/library.cr @@ -509,13 +509,15 @@ class Title ary = @entries.zip(percentage_ary) .sort { |a_tp, b_tp| a_tp[1] <=> b_tp[1] } .map { |tp| tp[0] } - when .auto? + else + unless opt.method.auto? + Logger.warn "Unknown sorting method #{opt.not_nil!.method}. Using " \ + "Auto instead" + end sorter = ChapterSorter.new @entries.map { |e| e.title } ary = @entries.sort do |a, b| sorter.compare a.title, b.title end - else - raise "Unknown sorting method #{opt.not_nil!.method}" end ary.reverse! unless opt.not_nil!.ascend @@ -800,8 +802,6 @@ class Library ary = titles case opt.not_nil!.method - when .auto? - ary.sort! { |a, b| compare_numerically a.title, b.title } when .time_modified? ary.sort! { |a, b| a.mtime <=> b.mtime } when .progress? @@ -809,7 +809,11 @@ class Library a.load_percentage(username) <=> b.load_percentage(username) end else - raise "Unknown sorting method #{opt.not_nil!.method}" + unless opt.method.auto? + Logger.warn "Unknown sorting method #{opt.not_nil!.method}. Using " \ + "Auto instead" + end + ary.sort! { |a, b| compare_numerically a.title, b.title } end ary.reverse! unless opt.not_nil!.ascend