/*
* Copyright (c) 2015 Spotify AB.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 com.spotify.heroic.shell.task;
import com.spotify.heroic.dagger.CoreComponent;
import com.spotify.heroic.shell.AbstractShellTaskParams;
import com.spotify.heroic.shell.ShellIO;
import com.spotify.heroic.shell.ShellTask;
import com.spotify.heroic.shell.TaskName;
import com.spotify.heroic.shell.TaskParameters;
import com.spotify.heroic.shell.TaskUsage;
import dagger.Component;
import eu.toolchain.async.AsyncFramework;
import eu.toolchain.async.AsyncFuture;
import org.kohsuke.args4j.Option;
import javax.inject.Inject;
@TaskUsage("(Test) Test to print some lines")
@TaskName("test-print")
public class TestPrint implements ShellTask {
private final AsyncFramework async;
@Inject
public TestPrint(AsyncFramework async) {
this.async = async;
}
@Override
public TaskParameters params() {
return new Parameters();
}
@Override
public AsyncFuture<Void> run(final ShellIO io, final TaskParameters base) throws Exception {
final Parameters params = (Parameters) base;
for (long i = 0; i < params.count; i++) {
io.out().println(String.format("Count: %08d", i));
}
return async.resolved();
}
private static class Parameters extends AbstractShellTaskParams {
@Option(name = "--count", usage = "Number of lines to print")
private long count = 10000;
}
public static TestPrint setup(final CoreComponent core) {
return DaggerTestPrint_C.builder().coreComponent(core).build().task();
}
@Component(dependencies = CoreComponent.class)
interface C {
TestPrint task();
}
}