<commit_before>//
//  Created by <NAME> on 2021/02/17.
//
//  This file is part of Hipstapaper.
//
//  Hipstapaper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Hipstapaper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Hipstapaper.  If not, see <http://www.gnu.org/licenses/>.
//

import SwiftUI

extension Alert {
    public init(_ error: UFError, dismissAction: @escaping () -> Void = {}) {
        if let error = error as? RUFError {
            precondition(error.options.count == 1, "Currently only 1 recovery option is supported")
            self.init(title: Text(error.title),
                      message: Text(error.message),
                      primaryButton: .init(error.options[0]),
                      secondaryButton: .cancel(Text(error.dismissButtonTitle),
                                               action: dismissAction))
        } else {
            self.init(title: Text(error.title),
                      message: Text(error.message),
                      dismissButton: .cancel(Text(error.dismissButtonTitle),
                                             action: dismissAction))
        }
    }
}

extension Alert.Button {
    public init(_ option: RecoveryOption) {
        if option.isDestructive {
            self = .destructive(Text(option.title), action: option.perform)
        } else {
            self = .default(Text(option.title), action: option.perform)
        }
    }<commit_msg>broke up initialization code<commit_after>//
//  Created by <NAME> on 2021/02/17.
//
//  This file is part of Hipstapaper.
//
//  Hipstapaper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Hipstapaper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Hipstapaper.  If not, see <http://www.gnu.org/licenses/>.
//

import SwiftUI

extension Alert {
    public init(_ error: UFError, dismissAction: @escaping () -> Void = {}) {
        if let error = error as? RUFError {
            self.init(RUFError: error, dismissAction: dismissAction)
        } else {
            self.init(UFError: error, dismissAction: dismissAction)
        }
    }
    
    private init(UFError error: UFError, dismissAction: @escaping () -> Void) {
        self.init(title: Text(error.title),
                  message: Text(error.message),
                  dismissButton: .cancel(Text(error.dismissButtonTitle),
                                         action: dismissAction))
    }
    
    private init(RUFError error: RUFError, dismissAction: @escaping () -> Void) {
        precondition(error.options.count == 1, "Currently only 1 recovery option is supported")
        self.init(title: Text(error.title),
                  message: Text(error.message),
                  primaryButton: .init(error.options[0]),
                  secondaryButton: .cancel(Text(error.dismissButtonTitle),
                                           action: dismissAction))
    }
}

extension Alert.Button {
    public init(_ option: RecoveryOption) {
        if option.isDestructive {
            self = .destructive(Text(option.title), action: option.perform)
        } else {
            self = .default(Text(option.title), action: option.perform)
        }
    }
{'fraction_non_alphanumeric': 0.09858467545143973, 'fraction_numerical': 0.005856515373352855, 'mean_word_length': 2.1482334869431643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188307', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1053, 'n_words': 365}