Skip to content

Commit

Permalink
feat(cli): Print artifact-specific version (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored Apr 13, 2017
1 parent 1c57084 commit 7dca740
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,7 @@ hal version bom VERSION [parameters]
```
#### Parameters
`VERSION`: The version whose Bill of Materials (BOM) to lookup.
* `--artifact-name`: When supplied, print the version of this artifact only.
* `--no-validate`: (*Default*: `false`) Skip validation.

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand;
import com.netflix.spinnaker.halyard.cli.command.v1.config.AbstractConfigCommand;
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon;
import com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler;
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils;
import com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration;
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiPrinter;
import com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials;
import com.netflix.spinnaker.halyard.core.registry.v1.Versions;
import lombok.AccessLevel;
import lombok.Getter;

Expand All @@ -53,6 +51,12 @@ public class BomVersionCommand extends AbstractConfigCommand {
"get the BOM for whatever version of Spinnaker you are currently configuring."
);

@Parameter(
names = "--artifact-name",
description = "When supplied, print the version of this artifact only."
)
String artifactName;

@Override
public String getMainParameter() {
return "VERSION";
Expand All @@ -74,10 +78,18 @@ public String getVersion() {

@Override
protected void executeThis() {
new OperationHandler<BillOfMaterials>()
.setFormat(AnsiFormatUtils.Format.YAML)
BillOfMaterials bom = new OperationHandler<BillOfMaterials>()
.setOperation(Daemon.getBillOfMaterials(getVersion()))
.setFailureMesssage("Failed to get Bill of Materials for version " + getVersion())
.get();

String result;
if (artifactName == null) {
result = AnsiFormatUtils.format(AnsiFormatUtils.Format.YAML, bom);
} else {
result = bom.getArtifactVersion(artifactName);
}

AnsiPrinter.println(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTask;
import com.netflix.spinnaker.halyard.core.tasks.v1.DaemonTaskHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/versions")
Expand Down

0 comments on commit 7dca740

Please sign in to comment.