mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 16:02:26 -05:00 
			
		
		
		
	Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config * replace many many instances of config * move more stuff => viper * properly remove urfave * move some flags to root command * add testrig commands to root * alias config file keys * start adding cli parsing tests * reorder viper init * remove config path alias * fmt * change config file keys to non-nested * we're more or less in business now * tidy up the common func * go fmt * get tests passing again * add note about the cliparsing tests * reorganize * update docs with changes * structure cmd dir better * rename + move some files around * fix dangling comma
This commit is contained in:
		
					parent
					
						
							
								182b4eea73
							
						
					
				
			
			
				commit
				
					
						0884f89431
					
				
			
		
					 487 changed files with 46667 additions and 8831 deletions
				
			
		
							
								
								
									
										95
									
								
								vendor/github.com/magiconair/properties/parser.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								vendor/github.com/magiconair/properties/parser.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,95 @@ | |||
| // Copyright 2018 Frank Schroeder. All rights reserved. | ||||
| // Use of this source code is governed by a BSD-style | ||||
| // license that can be found in the LICENSE file. | ||||
| 
 | ||||
| package properties | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"runtime" | ||||
| ) | ||||
| 
 | ||||
| type parser struct { | ||||
| 	lex *lexer | ||||
| } | ||||
| 
 | ||||
| func parse(input string) (properties *Properties, err error) { | ||||
| 	p := &parser{lex: lex(input)} | ||||
| 	defer p.recover(&err) | ||||
| 
 | ||||
| 	properties = NewProperties() | ||||
| 	key := "" | ||||
| 	comments := []string{} | ||||
| 
 | ||||
| 	for { | ||||
| 		token := p.expectOneOf(itemComment, itemKey, itemEOF) | ||||
| 		switch token.typ { | ||||
| 		case itemEOF: | ||||
| 			goto done | ||||
| 		case itemComment: | ||||
| 			comments = append(comments, token.val) | ||||
| 			continue | ||||
| 		case itemKey: | ||||
| 			key = token.val | ||||
| 			if _, ok := properties.m[key]; !ok { | ||||
| 				properties.k = append(properties.k, key) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		token = p.expectOneOf(itemValue, itemEOF) | ||||
| 		if len(comments) > 0 { | ||||
| 			properties.c[key] = comments | ||||
| 			comments = []string{} | ||||
| 		} | ||||
| 		switch token.typ { | ||||
| 		case itemEOF: | ||||
| 			properties.m[key] = "" | ||||
| 			goto done | ||||
| 		case itemValue: | ||||
| 			properties.m[key] = token.val | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| done: | ||||
| 	return properties, nil | ||||
| } | ||||
| 
 | ||||
| func (p *parser) errorf(format string, args ...interface{}) { | ||||
| 	format = fmt.Sprintf("properties: Line %d: %s", p.lex.lineNumber(), format) | ||||
| 	panic(fmt.Errorf(format, args...)) | ||||
| } | ||||
| 
 | ||||
| func (p *parser) expect(expected itemType) (token item) { | ||||
| 	token = p.lex.nextItem() | ||||
| 	if token.typ != expected { | ||||
| 		p.unexpected(token) | ||||
| 	} | ||||
| 	return token | ||||
| } | ||||
| 
 | ||||
| func (p *parser) expectOneOf(expected ...itemType) (token item) { | ||||
| 	token = p.lex.nextItem() | ||||
| 	for _, v := range expected { | ||||
| 		if token.typ == v { | ||||
| 			return token | ||||
| 		} | ||||
| 	} | ||||
| 	p.unexpected(token) | ||||
| 	panic("unexpected token") | ||||
| } | ||||
| 
 | ||||
| func (p *parser) unexpected(token item) { | ||||
| 	p.errorf(token.String()) | ||||
| } | ||||
| 
 | ||||
| // recover is the handler that turns panics into returns from the top level of Parse. | ||||
| func (p *parser) recover(errp *error) { | ||||
| 	e := recover() | ||||
| 	if e != nil { | ||||
| 		if _, ok := e.(runtime.Error); ok { | ||||
| 			panic(e) | ||||
| 		} | ||||
| 		*errp = e.(error) | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue