001package co.codewizards.cloudstore.client; 002 003import java.util.UUID; 004 005import org.kohsuke.args4j.Argument; 006 007import co.codewizards.cloudstore.core.oio.File; 008import co.codewizards.cloudstore.core.repo.local.LocalRepoRegistry; 009import co.codewizards.cloudstore.core.repo.local.LocalRepoRegistryImpl; 010 011/** 012 * {@link SubCommand} implementation for showing information about a repository in the local file system. 013 * 014 * @author Marco หงุ่ยตระกูล-Schulze - marco at nightlabs dot de 015 */ 016public class DropRepoAliasSubCommand extends SubCommand 017{ 018 @Argument(metaVar="<alias>", index=0, required=true, usage="The alias to be dropped.") 019 private String alias; 020 021 public DropRepoAliasSubCommand() { } 022 023 @Override 024 public String getSubCommandDescription() { 025 return "Drop an alias."; 026 } 027 028 @Override 029 public void run() throws Exception { 030 LocalRepoRegistry localRepoRegistry = LocalRepoRegistryImpl.getInstance(); 031 UUID oldRepositoryId = localRepoRegistry.getRepositoryId(alias); 032 033 File oldLocalRoot = null; 034 if (oldRepositoryId != null) { 035 oldLocalRoot = localRepoRegistry.getLocalRoot(oldRepositoryId); 036 if (oldLocalRoot == null || !oldLocalRoot.exists()) { 037 // orphaned entry to be ignored (should be cleaned up after a while, anyway) 038 oldRepositoryId = null; 039 oldLocalRoot = null; 040 } 041 } 042 043 if (oldRepositoryId != null) { 044 localRepoRegistry.removeRepositoryAlias(alias); 045 System.out.println(String.format("Dropped alias '%s' for repository %s (local-root '%s').", alias, oldRepositoryId, oldLocalRoot)); 046 } 047 else { 048 System.out.println(String.format("WARNING: The alias '%s' does not exist.", alias)); 049 } 050 } 051}