File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ All notable changes to `src-cli` are documented in this file.
1313
1414### Added  
1515
16+ -  ` src users delete `  now asks for confirmation to delete all users when no user ID is provided. [ #470  ] ( https://github.com/sourcegraph/src-cli/pull/470 ) 
17+ 
1618### Changed  
1719
1820### Fixed  
Original file line number Diff line number Diff line change 11package  main
22
33import  (
4+ 	"bufio" 
45	"context" 
56	"flag" 
67	"fmt" 
8+ 	"os" 
9+ 	"strconv" 
10+ 	"strings" 
711
812	"github.com/sourcegraph/src-cli/internal/api" 
913)
@@ -44,6 +48,37 @@ Examples:
4448
4549		client  :=  cfg .apiClient (apiFlags , flagSet .Output ())
4650
51+ 		if  * userIDFlag  ==  ""  {
52+ 			query  :=  `query UsersTotalCountCountUsers { users { totalCount } }` 
53+ 
54+ 			var  result  struct  {
55+ 				Users  struct  {
56+ 					TotalCount  int 
57+ 				}
58+ 			}
59+ 			ok , err  :=  client .NewQuery (query ).Do (context .Background (), & result )
60+ 			if  err  !=  nil  ||  ! ok  {
61+ 				return  err 
62+ 			}
63+ 
64+ 			fmt .Printf ("No user ID specified. This would delete %d users.\n Type in this number to confirm and hit return: " , result .Users .TotalCount )
65+ 			reader  :=  bufio .NewReader (os .Stdin )
66+ 			text , err  :=  reader .ReadString ('\n' )
67+ 			if  err  !=  nil  {
68+ 				return  err 
69+ 			}
70+ 
71+ 			count , err  :=  strconv .Atoi (strings .TrimSpace (text ))
72+ 			if  err  !=  nil  {
73+ 				return  err 
74+ 			}
75+ 
76+ 			if  count  !=  result .Users .TotalCount  {
77+ 				fmt .Println ("Number does not match. Aborting." )
78+ 				return  nil 
79+ 			}
80+ 		}
81+ 
4782		query  :=  `mutation DeleteUser( 
4883  $user: ID! 
4984) { 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments