core
core copied to clipboard
CLI: Implement init command
Parent Issue
No response
Task
The CLI should have an init
command that makes the installation and configuration process smoother. So, the init
should ask for:
- An URL: the dotcms instance the user wants to connect to
- User
- Password
Using the information provided, the CLI should:
- Create or update the .env file
- Create the dot-service.yml (and the .dotcms folder if not exists) This code can be used as reference:
String homeDirectory = System.getProperty("user.home");
this.filePath = Paths.get(homeDirectory, ".dotcms", "folder", "myfile.txt");
Files.createDirectories(filePath.getParent());
try (BufferedWriter writer = Files.newBufferedWriter(filePath)) {
writer.write(content);
}
- Update the application.properties (if needed)
- Configure any other setting required by the CLI to run properly
- In case a user runs any command before running the
init
, the execution shouldn't fail with an error. The CLI should stop the execution with a warning saying that theinit
command should be run first.
Proposed Objective
Core Features
Proposed Priority
Priority 3 - Average
Acceptance Criteria
- [ ] Implement an
init
command with the given details - [ ] Provide doc and update the CLI Quick Start
- [ ] This issue should be solved with the implementation
External Links... Slack Conversations, Support Tickets, Figma Designs, etc.
No response
Assumptions & Initiation Needs
No response
Quality Assurance Notes & Workarounds
No response
Sub-Tasks & Estimates
No response
Note to QA: when this task is implemented, please test this other card
Note to QA: don't forget to remove any old .dot-service.yml
We missed the related changes for this ticket in the GHA code, resulting in this error:
2024-02-21T00:18:18.6284710Z [ERROR] ❗ Error in command [push] with message:
2024-02-21T00:18:18.6286804Z Cannot construct instance of `com.dotcms.model.config.ServiceBean`, problem: Cannot build ServiceBean, some of required attributes are not set [url]
2024-02-21T00:18:18.6288786Z at [Source: (sun.nio.ch.ChannelInputStream); li...
2024-02-21T00:18:18.7238899Z exec -a 'dotcms-cli' java -Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager -XX:+ExitOnOutOfMemoryError -cp . -jar /tmp/dot-cli/dot-cli.jar push /home/runner/work/dotCMS-test/dotCMS-test --token=***
2024-02-21T00:18:18.7241525Z run with -e or --errors for full details on the exception.
2024-02-21T00:18:18.7242660Z 1
2024-02-21T00:18:18.7244371Z Quarkus log file contents:
2024-02-21T00:18:18.7246460Z 2024-02-21 00:18:18,404 fv-az1255-429 dot-cli.jar[1742] INFO [com.dot.cli.com.DotExecutionStrategy] (main) Executing command: push
2024-02-21T00:18:18.7248972Z /home/runner/work/_temp/b58a177f-7c8f-44cb-a4cb-f200195d0115.sh: line 7: [: -ne: unary operator expected
2024-02-21T00:18:18.7251930Z 2024-02-21 00:18:18,627 fv-az1255-429 dot-cli.jar[1742] ERROR [com.dot.cli.com.OutputOptionMixin] (main) Error in command [push] with message:
2024-02-21T00:18:18.7254122Z Cannot construct instance of `com.dotcms.model.config.ServiceBean`, problem: Cannot build ServiceBean, some of required attributes are not set [url]
2024-02-21T00:18:18.7257359Z at [Source: (sun.nio.ch.ChannelInputStream); li... : com.fasterxml.jackson.databind.exc.ValueInstantiationException: Cannot construct instance of `com.dotcms.model.config.ServiceBean`, problem: Cannot build ServiceBean, some of required attributes are not set [url]
2024-02-21T00:18:18.7260403Z at [Source: (sun.nio.ch.ChannelInputStream); line: 5, column: 1] (through reference chain: java.util.ArrayList[0])
2024-02-21T00:18:18.7262079Z at com.fasterxml.jackson.databind.exc.ValueInstantiationException.from(ValueInstantiationException.java:47)
2024-02-21T00:18:18.7263935Z at com.fasterxml.jackson.databind.DeserializationContext.instantiationException(DeserializationContext.java:2047)
2024-02-21T00:18:18.7266875Z at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.wrapAsJsonMappingException(StdValueInstantiator.java:587)
2024-02-21T00:18:18.7269342Z at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.rewrapCtorProblem(StdValueInstantiator.java:610)
2024-02-21T00:18:18.7271424Z at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createUsingDelegate(StdValueInstantiator.java:647)
2024-02-21T00:18:18.7273207Z at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator.createUsingDelegate(StdValueInstantiator.java:306)
2024-02-21T00:18:18.7275157Z at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1397)
2024-02-21T00:18:18.7276989Z at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:351)
2024-02-21T00:18:18.7278844Z at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:184)
2024-02-21T00:18:18.7280689Z at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer._deserializeFromArray(CollectionDeserializer.java:355)
2024-02-21T00:18:18.7282538Z at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:244)
2024-02-21T00:18:18.7284335Z at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:28)
2024-02-21T00:18:18.7286130Z at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:322)
2024-02-21T00:18:18.7287709Z at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674)
2024-02-21T00:18:18.7289043Z at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3674)
2024-02-21T00:18:18.7290656Z at com.dotcms.api.client.model.YAMLFactoryServiceManagerImpl.services(YAMLFactoryServiceManagerImpl.java:58)
2024-02-21T00:18:18.7292269Z at com.dotcms.api.client.model.YAMLFactoryServiceManagerImpl_ClientProxy.services(Unknown Source)
2024-02-21T00:18:18.7294226Z at com.dotcms.cli.common.DotExecutionStrategy.execute(DotExecutionStrategy.java:67)
2024-02-21T00:18:18.7295760Z at io.quarkus.picocli.runtime.PicocliRunner$EventExecutionStrategy.execute(PicocliRunner.java:26)
2024-02-21T00:18:18.7296858Z at picocli.CommandLine.execute(CommandLine.java:2078)
2024-02-21T00:18:18.7298204Z at io.quarkus.picocli.runtime.PicocliRunner.run(PicocliRunner.java:40)
2024-02-21T00:18:18.7299406Z at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:124)
2024-02-21T00:18:18.7300856Z at io.quarkus.runtime.Quarkus.run(Quarkus.java:67)
2024-02-21T00:18:18.7301965Z at io.quarkus.runtime.Quarkus.run(Quarkus.java:41)
2024-02-21T00:18:18.7302821Z at io.quarkus.runner.GeneratedMain.main(Unknown Source)
2024-02-21T00:18:18.7304091Z Caused by: java.lang.IllegalStateException: Cannot build ServiceBean, some of required attributes are not set [url]
2024-02-21T00:18:18.7306210Z at com.dotcms.model.config.ServiceBean$Builder.build(ServiceBean.java:390)
2024-02-21T00:18:18.7307224Z at com.dotcms.model.config.ServiceBean.fromJson(ServiceBean.java:252)
2024-02-21T00:18:18.7308464Z at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2024-02-21T00:18:18.7309840Z at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2024-02-21T00:18:18.7442659Z at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2024-02-21T00:18:18.7444297Z at java.base/java.lang.reflect.Method.invoke(Method.java:566)
2024-02-21T00:18:18.7445975Z at com.fasterxml.jackson.databind.introspect.AnnotatedMethod.call1(AnnotatedMethod.java:109)
2024-02-21T00:18:18.7447903Z at com.fasterxml.jackson.databind.deser.std.StdValueInstantiator._createUsingDelegate(StdValueInstantiator.java:631)
2024-02-21T00:18:18.7448960Z ... 20 more
Internal QA: Needs work
- There isn't a way to edit existing configurations unless I manually delete the dot-services.yml and run the
dotcli init
again. Deleting configurations is possible but not editing to include new configurations. - The doc needs to be updated. Please take a look at these sections:
- https://github.com/dotCMS/core/tree/master/tools/dotcms-cli#getting-started
- https://github.com/dotCMS/core/tree/master/tools/dotcms-cli#available-commands
- https://github.com/dotCMS/core/tree/master/tools/dotcms-cli#cli-instance-configuration
- https://github.com/dotCMS/core/tree/master/tools/dotcms-cli#github-actions-integration
Internal QA: Passed.
After the tests performed, it is observed that all the requirements of the task are met, among which we find
- Creation of a configuration directory named .dotcms
- The dot-service.yml file where the configuration is stored
- The configuration can be updated through
dotCLI
- The corresponding documentation has been updated
- If you try to run any command before configuring the CLI configuration, you will receive an error message indicating that you need to run the config command first.
Fixed, tested using the latest CLI version on npm and it is working as expected