<commit_before>/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

aliasFile = new File(grailsSettings.userHome, '.grails/.aliases')

includeTargets << grailsScript("_GrailsArgParsing")
target(default: 'Configures aliases for grails commands') {
     def params   = argsMap.params
     if(!params) {
         if(argsMap.list) {
             listAliases()
         } else if(argsMap.delete) {
             removeAlias()
         } else {
             println usage()
             exit 1
         }
         exit 0
     }
     if(params.size() == 1) {
         showAlias()
     } else {
         configureAlias()
     }
 }

def configureAlias() {
    def params = argsMap.params
    def aliases = loadProperties()
    def numberOfParams = params.size()
    def alias = params[0]
    def value = params[1..-1].join(' ')
    aliases.put alias, value
    aliases.store(new FileWriter(aliasFile), null)
}

def removeAlias() {
    def aliasToDelete = argsMap.delete
    if(aliasToDelete == Boolean.TRUE) {
        println usage()
        exit 1
    }<commit_msg>GRAILS-8612 - prompt before overwriting existing alias<commit_after>/*
 * Copyright 2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

aliasFile = new File(grailsSettings.userHome, '.grails/.aliases')

includeTargets << grailsScript("_GrailsArgParsing")
target(default: 'Configures aliases for grails commands') {
     def params   = argsMap.params
     if(!params) {
         if(argsMap.list) {
             listAliases()
         } else if(argsMap.delete) {
             removeAlias()
         } else {
             println usage()
             exit 1
         }
         exit 0
     }
     if(params.size() == 1) {
         showAlias()
     } else {
         configureAlias()
     }
 }

def configureAlias() {
    def params = argsMap.params
    def aliases = loadProperties()
    def numberOfParams = params.size()
    def alias = params[0]
    if(aliases.containsKey(alias) && isInteractive) {
        def oldValue = aliases.get(alias)
        if(!confirmInput("An alias named ${alias} already exists.  The current value is ${oldValue}. Overwrite existing value? ")) {
            exit 0
        }
    }
    def value = params[1..-1].join(' ')
    aliases.put alias, value
    aliases.store(new FileWriter(aliasFile), null)
}

def removeAlias() {
    def aliasToDelete = argsMap.delete
    if(aliasToDelete == Boolean.TRUE) {
        println usage()
        exit 1
    }
{'fraction_non_alphanumeric': 0.09788434414668547, 'fraction_numerical': 0.009873060648801129, 'mean_word_length': 2.546, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4186263', 'n_tokens_mistral': 1001, 'n_tokens_neox': 972, 'n_words': 332}