<commit_before>/*
 * Copyright 2017 Rundeck, Inc. (http://rundeck.com)
 *
 * 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.
 */

package org.rundeck.client.tool.commands;


import org.rundeck.client.tool.InputError;
import org.rundeck.client.api.model.ProjectNode;
import org.rundeck.client.tool.extension.BaseCommand;
import org.rundeck.client.tool.options.NodeFilterOptions;
import org.rundeck.client.tool.options.NodeOutputFormatOption;
import org.rundeck.client.tool.options.ProjectNameOptions;
import org.rundeck.client.util.Format;
import picocli.CommandLine;

import java.io.IOException;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * @author greg
 * @since 11/22/16
 */
@CommandLine.Command(description = "List node resources.", name = "nodes")
public class Nodes extends BaseCommand {


    @CommandLine.Mixin
    ProjectNameOptions options;
    @CommandLine.Mixin
    NodeOutputFormatOption nodeOutputFormatOption;
    @CommandLine.Mixin
    NodeFilterOptions nodeFilterOptions;

    @CommandLine.Command(description = "List all nodes for a project.  You can use the -F/--filter to specify a node filter, or " +
            "simply add the filter on the end of the command")
    public void list() throws IOException, InputError {
        String project = getRdTool().projectOrEnv(options);
        Map<String, ProjectNode> body = apiCall(api -> api.listNodes(project, nodeFilterOptions.filterString()));
        if (!nodeOutputFormatOption.isOutputFormat()) {
            getRdOutput().info(String.format("%d Nodes%s in project %s:%n", body.size(),
                    nodeFilterOptions.isFilter() ? " matching filter" : "",
                    project
            ));
        }
        Function<ProjectNode, ?> field;
        if (nodeOutputFormatOption.isOutputFormat()) {
            field = Format.formatter(nodeOutputFormatOption.getOutputFormat(), ProjectNode::getAttributes, "%", "");<commit_msg>fix: options should be in child<commit_after>/*
 * Copyright 2017 Rundeck, Inc. (http://rundeck.com)
 *
 * 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.
 */

package org.rundeck.client.tool.commands;


import org.rundeck.client.tool.InputError;
import org.rundeck.client.api.model.ProjectNode;
import org.rundeck.client.tool.extension.BaseCommand;
import org.rundeck.client.tool.options.NodeFilterOptions;
import org.rundeck.client.tool.options.NodeOutputFormatOption;
import org.rundeck.client.tool.options.ProjectNameOptions;
import org.rundeck.client.util.Format;
import picocli.CommandLine;

import java.io.IOException;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;


/**
 * @author greg
 * @since 11/22/16
 */
@CommandLine.Command(description = "List node resources.", name = "nodes")
public class Nodes extends BaseCommand {

    @CommandLine.Command(description = "List all nodes for a project.  You can use the -F/--filter to specify a node filter, or " +
            "simply add the filter on the end of the command")
    public void list(@CommandLine.Mixin
                     ProjectNameOptions options,
                     @CommandLine.Mixin
                     NodeOutputFormatOption nodeOutputFormatOption,
                     @CommandLine.Mixin
                     NodeFilterOptions nodeFilterOptions) throws IOException, InputError {
        String project = getRdTool().projectOrEnv(options);
        Map<String, ProjectNode> body = apiCall(api -> api.listNodes(project, nodeFilterOptions.filterString()));
        if (!nodeOutputFormatOption.isOutputFormat()) {
            getRdOutput().info(String.format("%d Nodes%s in project %s:%n", body.size(),
                    nodeFilterOptions.isFilter() ? " matching filter" : "",
                    project
            ));
        }
        Function<ProjectNode, ?> field;
        if (nodeOutputFormatOption.isOutputFormat()) {
            field = Format.formatter(nodeOutputFormatOption.getOutputFormat(), ProjectNode::getAttributes, "%", "");
{'fraction_non_alphanumeric': 0.10192345825897284, 'fraction_numerical': 0.005552250644457664, 'mean_word_length': 3.4323374340949035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1793660', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1323, 'n_words': 396}